[英]Verifying that async task run with robolectric 3
I have a method that starts couple of async tasks on background thread: 我有一个方法可以在后台线程上启动几个异步任务:
public void fetchSome() {
new SomeTask1().execute();
new SomeTask2().execute();
new SomeTask3().execute();
}
How can I test that these three tasks are executed with Robolectric 3.0 . 如何测试这三个任务是用Robolectric 3.0执行的。
Before I would warn you that AsyncTask
are not good solution for performing background operations. 在我警告您AsyncTask
并不是执行后台操作的好解决方案之前。 Take a look to talks in internet what is so bad with AsyncTask
. 看一下互联网上的对话,用AsyncTask
什么不好的地方。
As for me you're trying to test too many things. 至于我,您正在尝试测试太多的东西。 I would split it. 我会分开的。
Test that your code is starting async tasks: 测试您的代码是否正在启动异步任务:
Test that your tasks are doing right job: 测试您的任务是否做得正确:
Test that your tasks update UI with result: 测试您的任务是否使用结果更新UI:
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.