Java – How do I create a robot test suite?

How do I create a robot test suite?… here is a solution to the problem.

How do I create a robot test suite?

Using the code below, the tests are not executed in the order I want.
test_homescreen executes before test_splashscreen.

I want to specify the tests to run and the order in which they are executed.
I believe I need to create a test suite, but I don’t know how to implement it.

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 test_splashscreen() first, followed by test_homescreen().

  2. Only test_homescreen() is executed

The article seems close to what I want, but I can’t take advantage of it. Too general. Android Robotium – How to manage the execution order of testcases?

Solution

As we know, Robotium runs test cases in alphabetical order. Therefore, to get better results, we can set up separate test cases for separate activities. Other test cases related to that activity later can be saved in the same package (separate packages are reserved for separate activities). This will help to run test cases for the same activity together. To change the test order, you can always use the alphabet when naming test cases. For example: “testAddSplash” will run before “testHomeScreen”.

You can also use the 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 must have a parameterless constructor and a constructor with string parameters, as shown below.

public MyTestCase(String name)
{ 
            setName(name); 
} 

Related Problems and Solutions