由网友(咖啡不解酒的醉)分享简介:你知道如何实现单元测试使用Robolectric AsyncTasks?任何指针将AP preciated。Do you know how to implement unit testing for AsyncTasks using Robolectric ? Any pointers will be appreci...
你知道如何实现单元测试使用Robolectric AsyncTasks?任何指针将AP preciated。
Do you know how to implement unit testing for AsyncTasks using Robolectric ? Any pointers will be appreciated.
推荐答案
呼叫执行(...)
的任务,然后等待结果电话Robolectric.runBackgroundTasks()/Robolectric.flushBackgroundThreadScheduler()那么你就可以断言。
Call execute(...)
on the task, then to wait for the result call Robolectric.runBackgroundTasks()
/Robolectric.flushBackgroundThreadScheduler()
then you can assert.
@Test
public void test() {
//create task
MyAsyncTask asyncTask = new MyAsyncTask();
//start task
asyncTask.execute(...);
//wait for task code
// Robolectric.runBackgroundTasks(); (pre 3.0)
Robolectric.flushBackgroundThreadScheduler(); //from 3.0
//can run asserts on result now
assert...(asyncTask.get());
}
相关推荐
最新文章