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.
How do you create unit tests for an Android activity that starts async tasks
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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!