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 t
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);
}
First off, relying on tests running in a specific order is bad. If they require one to run after another you should be asking yourself why are they separate tests at all? If they rely on the previous tests state any failure in a previous test will cause the next ones to fail.
Now having said that, you are probably saying I do not care i just want this to work. So for you I will give you the answer anyway. You can of course do as others have said and rename your tests to run in alphabetical order. But you seem to want more level of control, so here it is:
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTest(TestSuite.createTest(myTest.class, "test_splashscreen"));
suite.addTest(TestSuite.createTest(myTest.class, "test_homescreen"));
suite.addTest(TestSuite.createTest(myTest.class, "test_splashscreen"));
return suite;
}
}
This has lots of issues because you have to give the test name as a string so if you refactor the test name your suite will break (and lots of other reasons too for that matter). Typically a test suite is more used for grouping classes of tests together in one run.
you can name you test cases like this:
public void test1_whatever()....
public void test3_other()...
public void test2_mytest()...
and when you run them the order will be:
test1_whatever()
test2_mytest()
test3_other()