Wait for async callback in unit test

Is there any way of sleeping / waiting for an async job/callback in a unit test?

I'm trying to write tests for my audio provider sync delegate, and even though I intend to do some mocking of backends and downloads, i would also like to be able to have some tests that test the actual downloads, and for that I need to make the unit test wait until I get a callback from makeWebRequest.

Usually you shouldn't sleep or pause in Monkey C obivously, but this is a different beast, and I need to stop the unit test method from returning until I can produce a test result.

  • Do you really need a full integration test? If you anyway do a mocked test for the responses then maybe you only need to do another test, not written in Monkey C but any other language that tests the apis of the service you're using (I guess making sure that it didn't change and still working as your app expects)

  • Yeah, as I thought about it more, I think I should start with unit tests that just mocks the network interactions.

    It would be nice to be able to automate some more complex integration tests, to ensure that various scenarious works. But just mocking my api calls and the media download should get me far.

    As you say, I should probably test my backend apis in the backend code, not with the fronted (watch) app :)