10

I have seen all the examples on the web and it seems real simple. I have a bare-bones app that displays a string. I have a a Android JUnit test project that I created when the app was being created (eclipse asked if I wanted to create a test app).

When I run the test app (Run As --- Android JUnit) I see the following in the console....

[2010-02-27 00:45:03 - SimpleCalculatorTest]Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 [2010-02-27 00:45:12 - SimpleCalculatorTest]Test run complete

I do not see any of the code in the testcase being called. My testcase is a class that extends ActivityInstrumentationTestCase2. DDMS log shows : 02-27 00:44:58.521: WARN/TestGrouping(1275): Invalid Package: '' could not be found or has no tests

Any ideas? I have tried everything....

4

2 回答 2

10

如果您创建一个新的 ActivityInstrumentationTestCase2,那么您需要一个指向您要测试的类的默认构造函数。

前任:

public class TestappTest extends ActivityInstrumentationTestCase2<AppUnderTest> {

  public TestappTest() {
    super("my.package.app", AppUnderTest.class);
  }

  public void testApp() {
      // Testcase
  }
}
于 2010-03-05T00:39:34.073 回答
9

我有同样的问题。原因是构造函数——它不知何故有一个像这样的参数:

public SearchActivityTest(Class<SearchActivity> activityClass) {
    super("com.example.app", SearchActivity.class);
}

但它不应该有这样的参数:

public SearchActivityTest() {
    super("com.example.app", SearchActivity.class);
}

它对我有用。

于 2012-04-05T07:23:39.123 回答