1

I want to assert that activity is successfully created with given condition. However, there is nothing like

controller.get().isCreated

My code is:

@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)
}

Yes, if there is any exception, this test would fail. However, I want to explicitly assert that my activity is successfully created.

John
  • 1,139
  • 3
  • 16
  • 33
  • Have you searched on StackOverflow before posting your question? There is a very high chance that your question has been previously answered and your question might be closed for being a duplicate. Here are two that I looked up one using robolectric the other using espresso: https://stackoverflow.com/questions/5896088/testing-that-button-starts-an-activity-with-robolectric and https://stackoverflow.com/questions/25998659/espresso-how-can-i-check-if-an-activity-is-launched-after-performing-a-certain – MD Naseem Ashraf Mar 11 '19 at 02:27
  • @MDNaseemAshraf I cannot find answers from both of it. I want to use robolectric and the answer is too old and the solution is deprecated – John Mar 11 '19 at 02:42
  • You're referring to the accepted answers being from older version of robolectric. Scroll down and you'll see another answer for version 3 upwards. Linked here: https://stackoverflow.com/a/39674693/2119723 – MD Naseem Ashraf Mar 11 '19 at 02:45
  • Thank you for the information. But nextStartedActivity() returns null, because I didn't click any button. What I want is getCurrentActivity() – John Mar 11 '19 at 04:09

0 Answers0