Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Android TDD

1,046 views

Published on

A discussion about unit testing strategies and test-driven development on the Android platform including:

* Unit Testing & TDD Overview
* Android Testing Framework
* JUnit 4 + POJO Library
* Robolectric

Published in: Technology, Education
  • Be the first to comment

Android TDD

  1. 1. Android TDD January 25, 2012 Chuck Greb @ecgreb
  2. 2. Why Test?
  3. 3. Validate Requirements
  4. 4. Ensure Quality
  5. 5. Reduce Cost
  6. 6. Why Unit Test?
  7. 7. Test smallest possible units of code (in isolation)
  8. 8. Makes refactoring easier (regression suite)
  9. 9. Self-documenting code
  10. 10. Fakes Mocks Stubs
  11. 11. Why TDD? (Test-Driven Development)
  12. 12. Improves Architecture
  13. 13. Reduced debugging time
  14. 14. Red -> Green -> Refactor
  15. 15. Tests must be fast!
  16. 16. Other kinds of tests?
  17. 17. Inverted Testing Pyramid
  18. 18. (Un-Inverted) Testing Pyramid
  19. 19. QA Job Security
  20. 20. Unit Testing is Awesome!!
  21. 21. Testing Approaches ● F@#% It! ● Manual ● Monkey Testing ● Android Testing Framework ● JUnit 4 + POJOs ● Robolectric ● Custom
  22. 22. Testing Approaches ● F@#% It! ● Manual ● Monkey Testing ● Android Testing Framework ● JUnit 4 + POJOs ● Robolectric ● Custom
  23. 23. Android Testing Framework
  24. 24. JUnit 3 + Instrumentation
  25. 25. Android Testing Framework
  26. 26. Test Case Classes ● TestCase ● AndroidTestCase ● ActivityTestCase ● ActivityUnitTestCase ● ServiceTestCase ● ProviderTestCase2 ● ActivityInstrumentationTestCase2
  27. 27. Android Mocks
  28. 28. HelloAndroidActivity
  29. 29. main.xml
  30. 30. StringBling
  31. 31. HelloAndroidActivityTest
  32. 32. Success!!!
  33. 33. Compile, dex, package, and install two APKs on emulator or device
  34. 34. Additional Challenges ● Classes and methods declared final ● Lack of interfaces ● Non-public constructors ● Static methods
  35. 35. JUnit 4 + POJOs
  36. 36. HelloAndroidActivityJUnitTest
  37. 37. StringBling
  38. 38. StringBlingTest
  39. 39. Success!!!
  40. 40. But we want to test ALL our code
  41. 41. Robolectric
  42. 42. Robolectric Test-Drive Your Android Code
  43. 43. Shadow ObjectsShadow Objects
  44. 44. Shadow Objects in Action
  45. 45. View and Resource Loading
  46. 46. HelloAndroidActivityRobolectricTest
  47. 47. Success!!!
  48. 48. More fun with Shadows
  49. 49. Using ShadowImageView
  50. 50. Using ShadowActivity
  51. 51. Write your own custom shadows
  52. 52. Contribute to Robolectric
  53. 53. Resources ● developer.android.com/guide/topics/testing ● junit.org ● pivotal.github.com/robolectric
  54. 54. Reading ● Robert C. Martin (Uncle Bob) ● Michael Feathers ● Kent Beck
  55. 55. Find your testing Zen
  56. 56. Chuck Greb @ecgreb http://ecgreb.com/blog https://github.com/ecgreb/StringBling

×