Slide 1

Slide 1 text

TEST DRIVEN DEVELOPMENT FOR ANDROID APPLICATIONS CODIFY 2.0 MEETUP

Slide 2

Slide 2 text

Hi, I’m Adora! Full Stack Web Developer Google Associate Android Developer Writer, adorahack.com Twitter: @theadoranwodo, @adorahack GitHub: @adoranwodo 2

Slide 3

Slide 3 text

“ Without requirements or design, programming is the art of adding bugs to an empty text file. - Louis Srygley 3

Slide 4

Slide 4 text

4 Don’t be like this...

Slide 5

Slide 5 text

5 Test Driven Development

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

7 ● Cleaner code ● Rapid feedback on failures ● Maintainable and scalable code ● Confidence ● Safe refactoring ● Focus Test Driven Development

Slide 8

Slide 8 text

8 The Testing Pyramid UI Tests Integration Tests Unit Tests

Slide 9

Slide 9 text

1. UNIT TESTS ( Small Tests ) 9

Slide 10

Slide 10 text

10 ● Test methods, classes or components in isolation from production systems. ● Verifies that the logic of individual units is correct ● Very fundamental Unit Tests

Slide 11

Slide 11 text

Types of unit tests ● Local Tests ● Instrumented Tests Frameworks used for unit tests ● Roboelectric ● Mokito 11 Unit Tests in Android

Slide 12

Slide 12 text

12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

2. INTEGRATION TESTS ( Medium Tests ) 14

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

3. UI TESTS ( Large Tests ) 18

Slide 19

Slide 19 text

19 ● Test that key end-user tasks work well on emulators and actual devices ● Evaluate your apps functionality as a whole UI Tests

Slide 20

Slide 20 text

Tools for UI tests ● Espresso ● UI Automator ● Robotium ● Selendroid 20 UI Tests in Android

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

22

Slide 23

Slide 23 text

23

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

4. WRITING BASIC TESTS 25

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

28 git clone https://github.com/AdoraNwodo/testingexample.git

Slide 29

Slide 29 text

Thanks! Website: www.adoranwodo.com Blog: www.adorahack.com GitHub: @adoranwodo Twitter: @theadoranwodo, @adorahack 29