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!

C4861b1dfdf3bbb21faec4a1acdf183d?s=128

Ellen Shapiro

May 21, 2015
Tweet

Transcript

  1. 2.

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

    Java — Has subclassable test runners
  2. 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.
  3. 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*
  4. 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
  5. 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
  6. 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.
  7. 8.
  8. 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