Friday, 5 July 2013

Running tests Test running startedTest running failed: Unable to find instrumentation info for: ComponentInfo{ [package.name]/android.test.InstrumentationTestRunner} Empty test suite.

I have been trying to run tests using Intellij's Android Studio. So I started here and used the IDE to help me create everything I needed. Failed horribly. Then I followed this and kept receiving this HELPFUL message:

Running tests
Test running started
Test running failed: Unable to find instrumentation info for: ComponentInfo{pacakge.name/android.test.InstrumentationTestRunner}
Empty test suite.

like a billion times!

 These are the things I have learnt:

  • Android/Studio use JUnit 3 so the constructor for your test suite MUST NOT have any parameters (aka don't let Studio create a constructor for you because it will add a parameter and JUnit will not be able to find your test suite):
  • public class TestMainActivity extends ActivityInstrumentationTestCase2<MainActivity> {
    public TestMainActivity() {
    super(MainActivity.class);
    }
    }


  • Your test needs to be in:
    yourModuleDir/src/instrumentTest/java/
    More info
  • The package of your test needs to be different from the package of the class you want to test, i.e: if the package for your activity is
    com.mypacakge.tortoise
    view raw tortoise.java hosted with ❤ by GitHub

    then the test should be in
    com.mypacakge.tortoise.test
  • Don't bother trying to run it from the IDE (don't believe this)
    • Start your emulator
    • Go to <yourProjectDir> (or where your gradlew is)
    • Run ./gradlew connectedInstrumentTest
    • The results can be found at:
      yourProjectDir/yourModuleDir/build/reports/instrumentTests/connected/index.html