Sometimes itβs tempting to test things that you usually donβt test with Unit Testing. This mainly comes from a lack of understanding and a desire to experience everything. And then you realize that you donβt know how to test it with unit testing.
Better ask yourself - what am I testing here?
Am I checking that the data is not available until the request completes?
Then you can write a non-asynchronous version of the test that will verify that the data is available after the request is complete.
I verify that the response was saved correctly after the request?
You can also test it with flags in your logic.
You can run all logic tests without performing asynchronous tests.
So, Iβll even ask you why, in your opinion, you need to test an asynchronous call?
Unit testing should be quick β so consider this one more reason not to test asynchronous calls. Imagine a system of continuous integration that will conduct this test - it will take extra time.
And after reading your comments on another answer - I think it is not quite easy to use asynchronous testing. For instance. Kent Beck in the TDD Book. that simultaneous testing of a device is possible, but a very rare case.
So - what and why do you really want to check?
source share