Robolectric在org.robolectric.res.ResBundle $ Value.compareTo(ResBundle.java:189)中间歇性NPE崩溃失败

时间:2016-07-12 02:00:56

标签: android robolectric

我在运行测试时出现间歇性故障。

java.lang.NullPointerException
    at org.robolectric.res.ResBundle$Value.compareTo(ResBundle.java:189)
    at org.robolectric.res.ResBundle$Value.compareTo(ResBundle.java:166)
    at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
    at java.util.ComparableTimSort.sort(ComparableTimSort.java:188)

以下代码

@RunWith(RobolectricGradleTestRunner::class)
@Config(constants = BuildConfig::class, sdk = intArrayOf(21), packageName = "my.package")
class MyActivityTest {
    lateinit var myActivity : MyActivity

    @Before
    fun setup() {
        myActivity = MyActivity()
    }
}

特别在线

        myActivity = MyActivity()

1 个答案:

答案 0 :(得分:1)

显然修复是

@RunWith(RobolectricGradleTestRunner::class)
@Config(constants = BuildConfig::class, sdk = intArrayOf(21), packageName = "my.package")
class MyActivityTest {
    lateinit var myActivity : MyActivity

    @Before
    fun setup() {
        myActivity = Robolectric.buildActivity(MyActivity::class.java).get()
    }
}