HandlerThread始まり機能をテストするために失敗しました。その後Robolectric 3.0は、私が<a href="http://developer.android.com/reference/android/os/HandlerThread.html">HandlerThread</a>拡張する単純なクラス<code>Job</code>持っ
public class Job extends HandlerThread{
public Job(String name) {
super(name);
}
...
}
を、私はJob
& start()
を取得する機能を有しているJobUtils
クラスを持っていること:
public JobUtils {
public JobUtils() {
}
// I unit test this function in my test class below
public Job getAndStartJob(String name) {
Job job = new Job(name);
job.start();
}
}
は、私は私のユニットテストでRobolectric 3.0を使用して、私はgetAndStartJob(String name)
functiをJobUtils
クラスをテスト上:私は私のユニットテストコードを実行すると、私はそれがRobolectricのように見える
Exception in thread "test-job” java.lang.NullPointerException
at org.robolectric.shadows.ShadowLooper.getMainLooper(ShadowLooper.java:70)
at org.robolectric.shadows.ShadowLooper.doLoop(ShadowLooper.java:85)
at org.robolectric.shadows.ShadowLooper.loop(ShadowLooper.java:76)
at android.os.Looper.loop(Looper.java)
at android.os.HandlerThread.run(HandlerThread.java:60)
はHandlerThread
(私のコードでjob
instace)を開始、または実行することはできませんエラーが発生しました
@RunWith(RobolectricTestRunner.class)
public class TestJobUtils{
@Test
public void testGetAndStartJob() {
JobUtils jobUtils = new JobUtils();
// error here
jobUtils.getAndStartJob(“test-job”);
…
}
}
私は何かが欠けている?どのようにこの問題を取り除く?