Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between InstrumentationTestCase and AndroidTestCase

I've been looking at this answer: https://stackoverflow.com/a/2055455/281460 and it does a great job of explaining the different test classes available for unit/integration testing in Android. One thing it does not explain, though, is the difference between InstrumentationTestCase and the other test case classes, specifically AndroidTestCase.

Could someone shed some light on this?

like image 722
jwir3 Avatar asked Oct 20 '14 16:10

jwir3


1 Answers

From the docs:

InstrumentationTestCase

A test case that has access to Instrumentation.

AndroidTestCase

Extend this if you need to access Resources or other things that depend on Activity Context.

AndroidTestCase is pretty well summarized via that link you posted. InstrumentationTestCase is higher up the class hierarchy from ActivityInstrumentationTestCase2. It's heavier weight than a plain AndroidTestCase, but it only exposes an Instrumentation object and no Activity, limiting its usefulness.

In reality, you'll probably never need this class, because it doesn't offer much (if any) performance advantage over ActivityInstrumentationTestCase2, which offers access to an Instrumentation object itself. In any case, if you want to know what you can do with an Instrumentation object, check out this or this.

like image 83
Krylez Avatar answered Nov 15 '22 06:11

Krylez