I am working with Android Studio and I need to add a unit tests to my project.
I read various tutorials, but nothing hepled me.
My problem is:
TestXMLParser.java:
public class TestXMLParser extends ActivityInstrumentationTestCase2<HomePageActivity> {
public TestXMLParser(Class<HomePageActivity> activityClass) {
super(activityClass);
}
@Override
public void setUp() throws Exception {
super.setUp();
//Controller.init((Activity)getContext());
}
@Override
public void tearDown() throws Exception {
super.tearDown();
}
public void testTrue() throws Exception {
assertTrue(true);
}
...
}
When I run it, I see this message:
junit.framework.AssertionFailedError: Class cz.cvut.kosapp.jUnitTests.TestXMLParser has no public constructor TestCase(String name) or TestCase()
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
I really do not know why. Other jUnit tests works well, for example when I use:
public class TestXMLParser extends AndroidTestCase { ...
in header, this works and tests are running correctly.
But I need use the Context (as a Activity) to run other code (in Controller class).
Do you have any idea how fix it?
Thank you for your comments.
You need to add either a default constructor or a constructor which takes a String
as a parameter. Adding the following default constructor with a call to the base class constructor should work:
public TestXMLParser() {
super(HomePageActivity.class);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.