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

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

    View Slide

  2. JUnit4: What is?
    — A huge, open-source testing library for Java
    — Has subclassable test runners

    View Slide

  3. Testing: Ye Olde Way
    — ActivityInstrumentationTestCase2extends 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.

    View Slide

  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*

    View Slide

  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

    View Slide

  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

    View Slide

  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.

    View Slide

  8. DEMO

    View Slide

  9. Question Time!

    View Slide

  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

    View Slide