how to create a robotium testsuite?

0
0

with the code below, the tests are not executed in the order I’d like.
test_homescreen is executed before test_splashscreen.

I’d like to specify the tests to run and their order of execution.
I believe I need to create a testsuite, but I don’t know how to implement that.

package com.myapp.test;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import com.myapp.R;
public class myTest extends ActivityInstrumentationTestCase2{
private static final String TARGET_PACKAGE_ID="com.myapp.test";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.myapp.gui.SplashScreen";
private static Class launcherActivityClass;
static{
try
{
launcherActivityClass
=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
public myTest ()throws ClassNotFoundException{
super(TARGET_PACKAGE_ID,launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception{
solo
= new Solo(getInstrumentation(),getActivity());
}
public void test_splashscreen() throws InterruptedException {
TextView splashAppVersion = (TextView) solo.getView(R.id.AppVersion);
assertTrue
(splashAppVersion.isShown());
}
public void test_homescreen() throws InterruptedException {
ListView lv = (ListView) solo.getView(R.id.List);
assertTrue
(lv.isShown());
}
@Override
public void tearDown() throws Exception {
try {
solo
.finishOpenedActivities();
} catch (Throwable e) {
e
.printStackTrace();
}
super.tearDown();
}
}

  1. execute first test_splashscreen(), then test_homescreen()

  2. execute only test_homescreen()

this post seems to be close to what I’d like but I have not been able to utilize it. too generic. Android Robotium – How to manage the execution order of testcases?

  • You must to post comments
0
0

as we know robotium runs the test cases in alphabetical order. So, for better result we can have separate test cases for separate activities. Later on other test cases related to that activity could be kept in same package (keep separate package for separate activity). this will help in running the test cases of same activity together. For changing the order of test you can always play with alphabets while naming the test cases. eg: “testAddSplash” will run before “testHomeScreen”.

You can also use suite() method:

public static final Test suite()
{
TestSuite testSuite = new TestSuite();
testSuite
.addTest(new MyTestCase("test1"));
testSuite
.addTest(new MyTestCase("test2"));
return testSuite;
}

Your test case musts have a no-arg constructor and a constructor with string parameter that looks like this.

public MyTestCase(String name)
{
setName
(name);
}
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website