我在运行测试时出现间歇性故障。
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()
答案 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()
}
}