Question

I have an Android Maven project (using android-maven-plugin) with a project and a test project.

I configured Maven to run the instrumentation tests and they are running without a problem from maven (mvn clean install).

However I'm unable to run the test from Eclipse. My test project contains two type of classes. Ones who inherit from AndroidTestCase and other that inherit from ActivityInstrumentationTestCase2

The test classes (in the test project) are build to target/classes.

I'm trying to run them as Android JUnit test but getting: Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException'

I saw Simple non-API Android JUnit test in Eclipse with android-maven-plugin? thread And it seems that the issue is caused by this bug (The runner is expecting the classes to be under bin/classes which they are not).

On the other hand, There is a work around of running the tests by doing run as regular JUnit test and adding the classes to the classpath. This solution did not work either. I get:

java.lang.RuntimeException: Stub!
    at junit.framework.TestSuite.<init>(TestSuite.java:6)
    at     org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:    102)
    at     org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.jav    a:59)
    at     org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at     org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at     org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at     org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Is there any way to be able to run test project from both Maven and Eclipse?

Was it helpful?

Solution

If you're running Android Instrumentation tests with Maven inside the Eclipse emulator you MUST:

  1. Run them in separate, integration test project/module.
  2. Put the tests into a NON-TEST source folder like src/main/java.

Please see the Maven Android Plugin Samples project for an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top