0
我正在爲android編寫單元測試,此測試應該驗證所使用的URL是否有效,我有一個url不變量和一個錯誤的方式進行測試,但測試沒有通過,我使用JUnit「測試未能運行到完成。儀器運行失敗,由於'java.lang.NullPointerException''
public class FeedControleTeste extends ActivityUnitTestCase<TelaFeed> {
private static Context context;
private final String FEED_ADDRESS = "http://noticias.gov.br/noticias/rss?id=AFSZW";
private FeedControle task1, task2;
private TelaFeed tela;
public FeedControleTeste() {
super(TelaFeed.class);
}
public void setUp() throws Exception {
context = getInstrumentation().getTargetContext();
tela = getActivity();
}
public void tearDown() throws Exception {
}
public void testTask() {
final CountDownLatch signal = new CountDownLatch(1);
try {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
task1 = new FeedControle(context, null);
task2 = new FeedControle(context, tela);
try {
task1.execute(FEED_ADDRESS);
task2.execute("url_errada");
} catch (Exception e) {
fail();
}
}
});
signal.await(30, TimeUnit.SECONDS);
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
這是我的錯誤:。
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'java.lang.NullPointerException''. Check device logcat for details"
那麼,logcat說什麼?我確信你知道他們在[這個部分...]中說了什麼...](http://www.quickmeme.com/img/94/94eb289f247f6e711a9975bed6783d1db4a15af4a9f2b7cd8f1a560a3bfb540a.jpg) – keyboardsurfer