Slide 1

Slide 1 text

Android Test-Driven Development Victoria Gonda

Slide 2

Slide 2 text

Hello, I'm Victoria! • Android Engineer at Buffer • Author at RayWenderlich.com • Hedgehog and cat owner

Slide 3

Slide 3 text

Android Test-Driven Development by Tutorials A book that teaches you to write sustainable, testable apps, as well as to apply testing strategies to legacy projects via Espresso and UI tests, code coverage and refactoring.

Slide 4

Slide 4 text

1. What is TDD Test-Driven Development basics

Slide 5

Slide 5 text

What to test? ▪ Do test code that: ▪ Contains logic ▪ Is fragile ▪ Will change

Slide 6

Slide 6 text

What to not test? ▪ Don't test code that: ▪ Is not yours ▪ Is generated ▪ Is throwaway

Slide 7

Slide 7 text

What is TDD ▪ Write a failing test ▪ Write code to make it pass ▪ Refactor

Slide 8

Slide 8 text

Why use TDD? ▪ Write intentionally ▪ Automatically document ▪ Keep maintainable code ▪ Have confidence in your code ▪ Develop faster ▪ Higher test coverage

Slide 9

Slide 9 text

2. The Pyramid How many tests should I have?

Slide 10

Slide 10 text

Testing Pyramid ▪ 10% UI Tests ▪ 20% Integration Tests ▪ 70% Unit Tests

Slide 11

Slide 11 text

Unit Tests ▪ Fast ▪ Focused ▪ Mock dependencies

Slide 12

Slide 12 text

Integration Tests ▪ Slower ▪ Test parts working together

Slide 13

Slide 13 text

UI Tests ▪ Slowest ▪ Running full app

Slide 14

Slide 14 text

3. Tools What can you use for testing?

Slide 15

Slide 15 text

Architecture ▪ Important for testability ▪ Design with tests in mind

Slide 16

Slide 16 text

Mockito ▪ "Tasty mocking framework for unit tests in Java ▪ Make "fake" dependencies

Slide 17

Slide 17 text

Robolectric ▪ "Robolectric is a framework that brings fast and reliable unit tests to Android." ▪ Android sandbox, off device

Slide 18

Slide 18 text

Espresso ▪ UI Testing ▪ "Use Espresso to write concise, beautiful, and reliable Android UI tests."

Slide 19

Slide 19 text

MockWebServer ▪ Stub network responses ▪ "A scriptable web server for testing HTTP clients."

Slide 20

Slide 20 text

4. Legacy apps What if it's not a new app?

Slide 21

Slide 21 text

Understand your boundaries ▪ Get familiar with architecture ▪ Think about constraints

Slide 22

Slide 22 text

High-Level Tests ▪ Usually Espresso tests ▪ Mock out network

Slide 23

Slide 23 text

“ ...break the app up into components and refactor things a component at a time.

Slide 24

Slide 24 text

Refactoring ▪ Make code more testable ▪ Helped by high-level tests

Slide 25

Slide 25 text

Refactor Tests ▪ As code changes, your tests will too

Slide 26

Slide 26 text

Handling Test Data ▪ Tests also need to be maintained

Slide 27

Slide 27 text

TDD is hard ▪ It takes practice ▪ You'll make mistakes

Slide 28

Slide 28 text

Android Test-Driven Development by Tutorials A book that teaches you to write sustainable, testable apps, as well as to apply testing strategies to legacy projects via Espresso and UI tests, code coverage and refactoring.

Slide 29

Slide 29 text

Thanks! @TTGonda VictoriaGonda.com