Android Test Orchestrator and custom Application class

Viewed 492

I gave a try to Android Test Orchestrator and it doesn't see any tests if Application class were changed. Pretty easy to reproduce.

  1. In Android Studio 3 preview Beta 6 create simple project with wizard
  2. Create custom runner like:
    class CustomTestRunner : AndroidJUnitRunner() {
      override fun newApplication(cl: ClassLoader?, className: String?,   context: Context?): Application {
       return super.newApplication(cl, TestApplicationClass::class.simpleName, context)
      }
    }
  1. Replace instrumentation runner with new one
  2. No test found after running instrumented tests

Any ideas? Looks like the Orchestrator depends on application class name from manifest.

I use this configuration to use special Dagger dependencies for tests.

1 Answers

I had the similar issue, with a custom test runner. Make sure that your TestApplicationClass does not crash at runtime. If the custom runner crashes then orchestrator will not be able to get information about the tests and will return the message:

No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

That is what happened to me in my custom runner.

Good luck!

Related