user1511140
user1511140

Reputation:

Android JUnit tests not detecting in Robotium

I am trying to run following Android JUnit3 test with robotium:

import android.test.ActivityInstrumentationTestCase2;
import com.package.sample.MyActivityClass;
import com.jayway.android.robotium.solo.Solo;

public class TestSample extends ActivityInstrumentationTestCase2<MyActivityClass> {
    private Solo solo;
    public TestSample() {
        super("com.package.sample", MyActivityClass.class);
    }

    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void clickbutton1() throws Exception{
        solo.clickOnButton("abc");
        solo.setActivityOrientation(Solo.LANDSCAPE);
        assertTrue(solo.searchText("load"));
    }

    @Override
    protected void tearDown() throws Exception{
        solo.finishOpenedActivities();
    }
}

The JUnit explores shows 0/0 tests runs. The debugger does not hit any code path mentioned here and Console outputs "test run finished"??:

Uploading MyAppTest.apk onto device 'emulator-5554'
Installing MyAppTest.apk...
Success!
Project dependency found, installing: MyApp
Uploading MyApp.apk onto device 'emulator-5554'
Installing MyApp.apk...
Success!
Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554
Collecting test information
Sending test information to Eclipse
Running tests...
Test run finished

Does anyone has an idea what is wrong? I have followed all steps in robotium tutorials religiously. I know there have been many questions around this but I have take care of all answers.

Also Robotium has similar problem with JUnit4 here.

Upvotes: 2

Views: 1958

Answers (2)

narancs
narancs

Reputation: 5294

I did everything what you said, but I still got error with 0/0 test.I had found the solution, which is related to constructors:

// I DELETED THIS CONSTRUCTOR
public TestHomeScreenTest(String pkg, Class<ScreenSlidePagerActivity> activityClass) {
    super(pkg, activityClass);
}


//GOOD SOLUTION:    
public TestHomeScreenTest() {
    super("com.dolphin.homescreen", ScreenSlidePagerActivity.class);
}

and it now WOOORKS ! :)

Upvotes: 1

BlackHatSamurai
BlackHatSamurai

Reputation: 23483

Yes, I know what is wrong.

In order to run your tests, you need to begin them with test. So your code should be like this:

import android.test.ActivityInstrumentationTestCase2;
import com.package.sample.MyActivityClass;
import com.jayway.android.robotium.solo.Solo;

public class TestSample extends ActivityInstrumentationTestCase2<MyActivityClass> {
    private Solo solo;
    public TestSample() {
        super("com.package.sample", MyActivityClass.class);
    }

    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    //the test methods MUST begin with test...
    public void testClickbutton1() throws Exception{
        solo.clickOnButton("abc");
        solo.setActivityOrientation(Solo.LANDSCAPE);
        assertTrue(solo.searchText("load"));
    }

    @Override
    protected void tearDown() throws Exception{
        solo.finishOpenedActivities();
    }
}

I had a similar issue awhile ago, and Robotium doesn't have the greatest documentation. I hope this helps you out :)

Upvotes: 3

Related Questions