Home - Programming - ActivityInstrumentationTestCase2 tests not running

I wasted a bit of time on this, so I thought I'd save the next guy some irritation.

I was attempting to write test cases for an activity. Actually, to be accurate, I was attempting to test some methods inside an activity without really bothering with the instrumentation, but that's not the point...

I created a JUnit project associated with my target project, created a new class extending ActivityInstrumentationTestCase2, filled in the expected boilerplate according to a tutorial video I found, created several test cases, and then attempted to run the project using the "Debug As..." | "Android JUnit Test".

And nothing happened.

After spinning my wheels trying all kinds of things that seemed to make sense but didn't change the outcome, I ran across this little tidbit. Instead of this:

	public CSMercuryActivityTest( Class activityClass ) {
		super( activityClass );

I used the parameter-less constructor and specified the class in the super constructor, like this:

	public CSMercuryActivityTest() {
		super( CSMercuryActivity.class );

And BOOM, all of a sudden it picked up all the cases I'd annotated with @SmallTest and named testXXX.

You're welcome.

Todd Grigsby