长话短说,我需要测试在AsyncTask的“doInBackground”方法中执行的代码。有没有办法在AsyncTask的抽象类保护方法中单元测试代码?
这在Android Studio与PowerMockito/Mockito/Robolectric/JUnit4。
我知道测试书面代码是不是很理想,
但我没有在这个词,我不能改变原来的代码。
这种情况:
public void methodToTest(){
new AsyncTask<Integer, Void, Boolean>() {
@Override
protected Boolean doInBackground(Integer... integers) {
//How to test code written over here ?
return false;
}
}
}
有没有办法解决这个问题的方法吗? 任何建议,非常赞赏
您是否看到http://stackoverflow.com/questions/15035850/testing-async-tasks-with-robolectric? –
@EugenMartynov在我的Google任务中,我没有遇到过那个人。如果我是正确的,那么这是关于验证AsyncTask本身的?我的目标是测试AsyncTask的doInBackground方法中使用的代码。如果我错了,请纠正我。 – user2417217
啊,我错过了你想测试抽象类。您可以随时在测试中扩展它,并在需要时以虚拟方式实现抽象方法 –