Robolectric,如何断言活动已创建,也不例外

时间:2019-03-11 02:16:32

标签: android unit-testing robolectric junit5

我想断言在给定条件下成功创建了活动。 但是,没有像

  

controller.get()。isCreated

我的代码是:

@get:Rule
val exception: ExpectedException = ExpectedException.none()

@Test
fun test_example() {
    // Given
    val intent = getMyIntent()

    // When
    val controller = Robolectric.buildActivity(
            MyActivity::class.java,
            intent
    ).setup()

    // Then
    // no exception is expected and
    assertTrue(controller != null)
}

是的,如果有任何异常,该测试将失败。 但是,我想明确声明我的活动已成功创建。

0 个答案:

没有答案
相关问题