When defining a junit test using the static suite method android assumes that the name of each test is also the name of a method. If this is not the case then the test runner fails to run. The following test class works correctly using the standard eclipse junit runner:
public class CustomTest extends TestCase { public CustomTest(String testName) { super(testName); } @Override protected void runTest() throws Throwable { Assert.fail("Test failed"); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new CustomTest("test1")); return suite; } } however running using the android test runner says that test1 passes! I have managed to trace this down to the following code in InstrumentationTestRunner: try { // Look for TimedTest annotation on both test class and test method if (test.getClass().getMethod(testName).isAnnotationPresent(TimedTest.class)) { mIsTimedTest = true; mIncludeDetailedStats = test.getClass().getMethod(testName).getAnnotation( TimedTest.class).includeDetailedStats(); } else if (test.getClass().isAnnotationPresent(TimedTest.class)) { mIsTimedTest = true; mIncludeDetailedStats = test.getClass().getAnnotation( TimedTest.class).includeDetailedStats(); } } catch (SecurityException e) { throw new IllegalStateException(e); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } The thrown IllegalStateException doesn't seem to be caught or reported anywhere which is I think why the eclipse plugin incorrectly reports the tests have passed. As this code is called before the test is run the test code is never called. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en