chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I am using Typemock Isolator version 7.3.2. I recently converted a synchronous library to async and have used async/await pattern. I am now trying to convert the corresponding unit tests and am running into issues with it. My code is as follows:

public async void LibraryMethod_InvokesSecondServiceOperation()
var library= new MyAsyncLibrary();
var service = library.Service;
var operation1Response= new Operation11Response();

Isolate.WhenCalled(() => service.Operation1(null, null)).WillReturn(operation1Response);

var operation2Response= new Operation2Response();
Isolate.WhenCalled(() => service.Operation2(null, null, null)).WillReturn(operation2Response);

var result= await library.MethodInvokingMultipleServiceOperationsAsynchronously();

Isolate.Verify.WasCalledWithAnyArguments(() => service.Operation2(null, null, null));

This does not work I get a null reference exception as the service operations are invoked with invalid arguments. This used to work when these calls were synchronous in nature. Can someone help me get these tests working again.

- A
asked by ashwin.seshadri (1.1k points)

2 Answers

0 votes
Hi Ashwin,

Thank you for the feedback.

We've designed Isolator to work best with unit tests, which in our case means testing logic on a single thread. In that sense, it's limited in support for multi-threaded code, but for the right reason.

What I suggest is that you try to test the code that runs on the separate thread and not the combination of multiple threads. It's not going to be a bad test - just not a unit test.

I'll be happy to help with writing these tests, so if you get stuck let me know.
answered by alex (17k points)
0 votes
Hi Ashwin.

Thanks for you lovely suggestion. As much as I'd love to unit test each and every little thread in a separate test, unfortunately we'd only recently started with automated tests. Time (the lack of) sometimes forces people to enclose existing code in a wrapper to be able to write integration-style tests against legacy and TDD-style for new code. And these contain logic that is responsible for loading things and running things in the right order, and facilitates communication between multiple VM's (cloud-app based app). These not only use multiple threads to monitor multiple queues and other things, but are actually also on physical different machines. These multi-threaded, multi-tiered, and scaling threads and processes need to be working together on the same data (relational) at the same time, and therefor needs to talk to each other so that they don't clash overwrite/supersede/miss each other's updates. A tool like TypeMock Racer would have been useful. Why did TypeMock stop its manufacturing?

Any case, got to go now, need figure out where my multiple-threaded bug is. Oh, wait, I can't. The tools won't let me ;)

answered by jovton (1.1k points)