I have a simple AsyncTask that performs some calculations. How can i unit test it?
Asked
Active
Viewed 3,604 times
1
-
check out the answer [here](http://stackoverflow.com/questions/8295003/best-way-to-manage-the-progressdialog-from-asynctask/8317071#8317071) to see if it helps. – yorkw Apr 21 '12 at 22:44
2 Answers
2
I don't see why you'd need to test it asynchronously. If your code is in the doInBackground method, you could just call that method from your test class and assert something with the result when it returns.

ZeroOne
- 3,041
- 3
- 31
- 52
-
@Shalmezad Then extend AsyncTask and create a new public method that calls the protected method there? – ZeroOne Jan 21 '14 at 14:59
-
1@Shalmezad `protected` is accessible in same package, thus following a convention of having tests in same package helps – Ivar Feb 20 '19 at 14:52
-
@AivarasPrudnikovas Good catch and thanks for the correction. Must've mistaken Java's protected with C++'s protected 4 years ago. – Shalmezad Feb 21 '19 at 18:47
0
I had found the following example, I think you should check this out: https://github.com/pivotal/RobolectricSample

narancs
- 5,234
- 4
- 41
- 60
-
try this please:https://github.com/android10/Inside_Android_Testing/tree/master/RobolectricSample – narancs Oct 25 '15 at 17:50