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

Test Driven Development for Android Applications

Adora Nwodo
November 30, 2018

Test Driven Development for Android Applications

This slides talks about test driven development and software testing in android applications, why we should test, and how we can test our android apps.

Adora Nwodo

November 30, 2018
Tweet

More Decks by Adora Nwodo

Other Decks in Technology

Transcript

  1. Hi, I’m Adora! Full Stack Web Developer Google Associate Android

    Developer Writer, adorahack.com Twitter: @theadoranwodo, @adorahack GitHub: @adoranwodo 2
  2. “ Without requirements or design, programming is the art of

    adding bugs to an empty text file. - Louis Srygley 3
  3. 6

  4. 7 • Cleaner code • Rapid feedback on failures •

    Maintainable and scalable code • Confidence • Safe refactoring • Focus Test Driven Development
  5. 10 • Test methods, classes or components in isolation from

    production systems. • Verifies that the logic of individual units is correct • Very fundamental Unit Tests
  6. Types of unit tests • Local Tests • Instrumented Tests

    Frameworks used for unit tests • Roboelectric • Mokito 11 Unit Tests in Android
  7. 12

  8. 13

  9. 15 • Integration tests are a subset of medium tests

    • Integrates several components • Run on emulators or real devices • Cloud-based services like Firebase Test Lab can be used Integration Tests
  10. Firebase Test Lab is a cloud-based app-testing infrastructure. With one

    operation, you can test your Android or iOS app across a wide variety of devices and device configurations, and see the results—including logs, videos, and screenshots—in the Firebase console. 16 Firebase Test Lab
  11. 17

  12. 19 • Test that key end-user tasks work well on

    emulators and actual devices • Evaluate your apps functionality as a whole UI Tests
  13. Tools for UI tests • Espresso • UI Automator •

    Robotium • Selendroid 20 UI Tests in Android
  14. 21

  15. 22

  16. 23

  17. 24

  18. 26 //app level build.grade testImplementation 'junit:junit:4.12' compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" //Sample test

    class AdditionUnitTest { private val instance = MainActivity::class.createInstance() @Test fun additionOneIsCorrect() { //Test Case 1: Two positive numbers Assert.assertEquals(12, instance.addition(3,9)) } } Sample Unit Test
  19. 27 //app level build.grade testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    androidTestImplementation 'com.android.support.test:rules:1.0.2' //Sample test @Test fun textViewsAreZeroOnLaunch(){ mActivityTestRule.launchActivity(null) //start activity //check results Espresso.onView(ViewMatchers.withId(R.id.teamA)).check(matches(withText("0"))) Espresso.onView(ViewMatchers.withId(R.id.teamB)).check(matches(withText("0"))) } Sample Instrumentation Test