Trying to run Android JUnit tests in Eclipse fails?

≡放荡痞女 提交于 2019-12-18 07:39:18

问题


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....


回答1:


If you create a new ActivityInstrumentationTestCase2 then you need a default constructor that points to the class that you want to test.

ex:

public class TestappTest extends ActivityInstrumentationTestCase2<AppUnderTest> {

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

  public void testApp() {
      // Testcase
  }
}



回答2:


I had the same problem. The reason was the constructor - it somehow had a parameter like this:

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

But it should have no parameters like this:

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

It worked for me.



来源:https://stackoverflow.com/questions/2346734/trying-to-run-android-junit-tests-in-eclipse-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!