I cannot get a trivial Robotium test running:
public class TapsTest extends ActivityUnitTestCase<Ad> {
public TapsTest() { super(Ad.class); }
Solo mSolo;
@Override
protected void setUp() throws Exception {
super.setUp();
mSolo = new Solo(getInstrumentation(), getActivity());
}
public void testTabTaps() {
assertTrue(mSolo.searchText("Latest")); // NPE thrown here
}
}
this test crashes consistently with
java.lang.RuntimeException: java.lang.NullPointerException
at com.jayway.android.robotium.solo.Searcher.searchFor(Searcher.java:113)
at com.jayway.android.robotium.solo.Searcher.searchWithTimeoutFor(Searcher.java:68)
at com.jayway.android.robotium.solo.Solo.searchText(Solo.java:442)
on both my two devices (Android 4.1.0 and 4.0.3) and ADV. Initially Robotium complained about the missing V4 support library (we do not need it for other purposes) so I added android-support-v13.jar. Now the class not found exception is gone but NPE remains. I also tried to start the activity manually:
Ad ado = startActivity(new Intent("android.intent.action.MAIN"), null, null);
mSolo = new Solo(getInstrumentation(), ado);
but NPE remains. I tried mSolo.searchButton("Go") and there is a button with this text on UI, and it is visible, and still the same NPE from the line 113 in Robotium.
The application itself starts and runs correctly if not under tests. Also, other ActivityUnitTestCase tests (without Robotium) run and pass without issues.
I tried to use robotium-solo-3.6.jar from Robotium website.
Is there any reason, you use ActivityUnitTestCase?
You should rather use ActivityInstrumentationTestCase2.
Then you have to change your constructor – add package as parameter.
Look here: http://code.google.com/p/robotium/wiki/Getting_Started