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

JUnit 4 + Android: Friends 4 Eva (AndroidListen...

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

May 21, 2015
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

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

    Java — Has subclassable test runners
  2. 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.
  3. 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*
  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* * - in theory
  5. 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
  6. JUnit4 Drawbacks — Assume handling is not presently working. —

    FlakyTest does not work with JUnit4 tests. — You have to static import a lot more stuff.
  7. 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