$30 off During Our Annual Pro Sale. View Details »

JUnit 4 + Android: Friends 4 Eva (AndroidListener Chicago, May 2015)

JUnit 4 + Android: Friends 4 Eva (AndroidListener Chicago, May 2015)

A quick look at the benefits of using the Android JUnit4 runner. Links to code and other fun stuff at the end!

Ellen Shapiro
PRO

May 21, 2015
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

  1. JUnit4 + Android: Friends 4 Eva Ellen Shapiro AndroidListener Chicago,

    May 2015
  2. JUnit4: What is? — A huge, open-source testing library for

    Java — Has subclassable test runners
  3. Testing: Ye Olde Way — ActivityInstrumentationTestCase2<T extends Activity> — Name

    of method to be tested starts with test — If something is temporarily broken, either delete it or comment it out. — Testing different data requires a separate test calling a private helper.
  4. Testing: Ye JUnit4 Way — Uses annotations instead of naming

    conventions — Allows tests to be marked as ignored — Runner has subclasses allowing all sorts of fancy things — Allows you to have tests skipped based on an assumption*
  5. Testing: Ye JUnit4 Way — Uses annotations instead of naming

    conventions — Allows tests to be marked as ignored — Runner has subclasses allowing all sorts of fancy things — Allows you to have tests skipped based on an assumption* * - in theory
  6. JUnit4 Benefits — Tests don't reference an activity unless they

    need to — Name things in a way that makes sense to YOU — Run the same test many times with different params
  7. JUnit4 Drawbacks — Assume handling is not presently working. —

    FlakyTest does not work with JUnit4 tests. — You have to static import a lot more stuff.
  8. DEMO

  9. Question Time!

  10. Links Galore! — AndroidListenerExamples: https://github.com/ designatednerd/AndroidListenerExamples — User Guide: https://code.google.com/p/android-test-

    kit/wiki/AndroidJUnitRunnerUserGuide — Google Sample: https://github.com/googlesamples/ android-testing/tree/master/testrunner/ AndroidJunitRunnerSample — JUnit Docs: http://junit.org/javadoc/latest/ index.html