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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With