Execution order of robotium tests

1,947 views
Skip to first unread message

Itay Roth

unread,
Feb 6, 2011, 5:14:37 AM2/6/11
to Robotium Developers
Hi,

It seems like Robotium runs my tests in alphabetical order, rather
than the order they're written.
Is there a way to control the order of execution?

Thanks,

Itay

Butters

unread,
Feb 6, 2011, 6:45:23 PM2/6/11
to Robotium Developers
its not Robotium, its Androids Instrumentation runner which runs the
test cases. And android's instrumentaion runner derives from JUnit, so
actually its JUnit.

marekdef

unread,
Feb 9, 2011, 4:36:08 PM2/9/11
to Robotium Developers
Hi,

I believe the order is determined by TestSuiteBuilder and in fact it
partially sorts according to fully qualified name.

I just posted a blog entry that mentions it partially:

http://blogprogramistyandroid.blogspot.com/2011/02/randomizing-order-of-tests.html

You can take a look at the RandomizingTestRunner.

I think you can:

1. Put the test(s) in order you want by sorting them in onStart()
a) with hardcoded values in TestRunner (not very convenient I guess)

b) with a variable passed to a bundle and collected onCreate() (take a
look at
http://www.google.com/codesearch/p?hl=en#5oTG8Wvrixk/trunk/android-x86/frameworks/base/test-runner/android/test/InstrumentationTestRunner.java&q=InstrumentationTestRunner%20onCreate&l=259)
and pass argument adb shell am instrument -e order "test1,test3,test4'
class/testrunner

(not sure how to launch in eclipse)

2. I believe you can write test as

test1() {
internal_test1()
internal_test2()
internal_test3()
}

so you know the order will be 1,2,3 but if 2 fails the 3rd is not
executed. I am not sure if you can live with that

3. You can 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);
}


The last method seem to be most convenient.

HTH

Mukesh Yadav

unread,
Mar 19, 2014, 4:41:53 AM3/19/14
to robotium-...@googlegroups.com
I am doing in this way.
Created a class which contains the order of execution of testsuit. For eg:

package com.android.test; 

import junit.framework.TestSuite;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;

public class AllTests extends  ActivityInstrumentationTestCase2<Activity> {

public AllTests(Class<Activity> activityClass) {
super(activityClass);
}

public static TestSuite suite() {
TestSuite t = new TestSuite();
t.addTestSuite(SplashScreenTest.class);
t.addTestSuite(MainLoginScreenTest.class);
t.addTestSuite(EmailSignUpScreenTest.class);
t.addTestSuite(EmailVerificationTest.class);
t.addTestSuite(EmailLoginScreenTest.class);
return t; 
}
@Override
public void setUp() throws Exception {
}
@Override
public void tearDown() throws Exception {
}

}

check the complete tutorial on below link:


Thanks,
Mukesh
Reply all
Reply to author
Forward
0 new messages