Possible errors while running test cases

While writing functional or unit test cases through Robotium or  InstrumentationTestCase if you get

TestCase class com.example.test.WelcomeActivityText is missing a public constructor with no parameters or a single String parameter

at run time then this must be because of your test project dint include a default constructor. That is

import com.example.WelcomeActivity;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;

public class WelcomeActivityText extends ActivityInstrumentationTestCase2<WelcomeActivity> {

    private Solo mSolo;
    public WelcomeActivityText() {
        super(WelcomeActivity.class);
    }
    
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mSolo = new Solo(getInstrumentation());
    }
    
    public void testWelcomeActivity(){
        assertEquals(WelcomeActivity.class, getActivity().getClass());
        mSolo.assertCurrentActivity("WelcomeActivity is not shown", WelcomeActivity.class);
    }

}

If you create a default constructor like the above code you can get ride of this error.

Invalid Package: ” could not be found or has no tests”

If you get this error means then please do check you have started your test case function with test as prefix (testWelcomeActivity).

Advertisements