views:

274

answers:

1

How do you create unit tests for an Android activity that starts async tasks in onCreate? I would like to test the result of these tasks.

A: 

It is hard to write tests for a lot of Android functionality, since you can't instantiate classes like Activity outside of Android.

You might be better off doing a true unit test...test the function whose behavior you care about in isolation. Don't try to test it in the context of async task, activity, etc.

You might need to refactor your code a little bit to be able to do that, but its worth it to have testable code!

Mayra