Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Testing

Android Testing

Discover testing for Android Development

Nguyen Truong Giang

June 11, 2018
Tweet

Other Decks in Programming

Transcript

  1. About me • Nguyen Truong Giang • Senior Android Engineer

    / Android Leader @ tiki.vn • Skype: gianguitpp • Email: [email protected] • https://github.com/talenguyen
  2. JVM

  3. JVM Device Instrumentation Unit Test
 (Logic with Context) JVM Unit

    Test
 (Fastest - Pure Logic) /test /androidTest
  4. JVM Device Instrumentation Unit Test
 (Logic with Context) Instrumentation UI

    Test JVM Unit Test
 (Fastest - Pure Logic) Non-UI UI /test /androidTest
  5. class ValidatorKtTest { @Test fun emailAddress() { assertThat(isEmailAddress("[email protected]")).isTrue() } @Test

    fun notEmailAddress() { assertThat(isEmailAddress("foo@tiki")).isFalse() } }
  6. @Test fun `login success then save token to LocalStorage`() {

    // Setup val mockedApiServices = mock<ApiServices>() val mockedLocalStorage = mock<LocalStorage>() val tested = UserRepository(InstantAppExecutors(), mockedApiServices, mockedLocalStorage) // given val token = "token" `when`(mockedApiServices.login(anyString(), anyString())) .thenReturn(just(ApiResponse.create(Response.success(token)))) // when tested.login("[email protected]", "bar") .observeForever(mock()) // then verify(mockedLocalStorage).setAccessToken(token) }
  7. UI (end to end) test • Verify whole system work

    • User interacts with UI components
  8. @Test fun invalidEmail() { // Input invalid email onView(withId(R.id.etUsername)) .perform(replaceText("giang"),

    closeSoftKeyboard()) // Verify invalid email message is shown onView(withId(R.id.tilUsername)) .check(matches(hasError(R.string.email_is_invalid))) // Verify submit button is disable onView(withId(R.id.btSubmit)) .check(matches(Matchers.not(isEnabled()))) }
  9. • Unit test for simple logic • Integration test to

    verify business logic • UI test for the rest
  10. • https://github.com/tikivn/AndroidTesting • Unit test: Validator • Integration test: UseRepository

    • get “access-token” from LocalStorage • login success then save “access-token” to LocalStorage