0

Trying to learn instrumentation testing scenarios. While going over the relevant documentation for the ActivityInstrumentationTestCase2, i learned that we can use the ActivityInstrumentationTestCase2 in conjunction with Espresso to write so called "functional" tests. Or at least that is what i understood from the relevant documentation.

However i ran into something called a ActivityUnitTestCase and a ServiceTestCase, which i had never heard of before. Trying to figure that out led me down a wild goose chase and now i am terribly lost here with so many verbiages to the whole Android testing paradigm.

  1. Considering from a high level that Android testing broadly falls into two buckets: Unit testing and functional testing. Out of the following, which falls under which.

    JUnit, JUnit4, TestCase, AndroidTestCase, ActivityInstrumentationTestCase2, ServiceTestCase, ApplicationTestCase, AndroidTestRunner, AndroidJUnitRunner, AndroidJUnit4

  2. What should be used when?

  3. Do any of them relate to the actual Unit testing (by which i mean POJO testing). I ask this because i have noticed some tutorial links in which the sample test case extends JUnit4/TestCase and is still termed a unit test whereas one of the links below does not extend anything at all and still works as a simple POJO test case. Which raises the question what exactly is the difference between a JUnit4 and simple POJO test class.

References that i have checked so far:

http://www.vogella.com/tutorials/AndroidTesting/article.html#androidtesting_creatingtestfolders

https://shaun.church/unit-testing-java-classes-in-android-studio/

Android Test Frameworks

Robolectric vs Android Test Framework

http://developer.android.com/tools/testing/testing_android.html

Any ideas, tips much appreciated. Thanks!

Community
  • 1
  • 1
user2511882
  • 9,022
  • 10
  • 51
  • 59

1 Answers1

1

What should be used when?

Most of what you listed is deprecated. JUnit4, using AndroidJUnitRunner, are the only items that are actively used for new development.

Do any of them relate to the actual Unit testing (by which i mean POJO testing)

Nowadays, in Android terms, "unit testing" means "running JUnit4 tests, perhaps with mocking frameworks, on the JVM of your development machine or CI server". JUnit4 is used for this, along with perhaps Mockito, Robolectric, etc.

Contrast this with "instrumentation testing", which means "running JUnit4 tests, perhaps with Espresso and/or UiAutomator, in an Android device or emulator". JUnit4 is still used here, and here you have access to the regular Android SDK. UiAutomator is used for integration testing (did App A successfully start App B's activity?).

Bear in mind that this particular split between "unit testing" and "instrumentation testing" is fairly new. Material that you read that is older than, say, mid-2015 might use those terms interchangeably, as we did not have official support for what is now called unit testing (though plenty of developers used Robolectric for this purpose before then as well).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I see, so the the gist being: Unit testing for Android = Junit4 + Mocks etc. and functional/instrumentation testing for Android = JUnit4 + Robotium/Espresso etc, is that correct ? – user2511882 Apr 30 '16 at 20:22
  • @user2511882: I'm skeptical about your use of "functional" (that's a somewhat amorphous term IMHO), but otherwise, yes, that is correct. – CommonsWare Apr 30 '16 at 20:24