假设有一个特定于android的测试用例,如下所示,因为android测试用例的运行顺序总是不一样,
public class MainActivityUnitTest extends
android.test.ActivityUnitTestCase<MainActivity> {
private int buttonId;
private MainActivity activity;
public MainActivityUnitTest() {
super(MainActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
Intent intent = new Intent(getInstrumentation().getTargetContext(),
MainActivity.class);
startActivity(intent, null, null);
activity = getActivity();
}
public void testLayout() {
buttonId = com.vogella.android.test.simpleactivity.R.id.button1;
assertNotNull(activity.findViewById(buttonId));
Button view = (Button) activity.findViewById(buttonId);
assertEquals("Incorrect label of the button", "Start", view.getText());
}
public void testLayoutFirst() {//some test cases specific code here ....}
public void testLayoutSecond() {//some test cases specific code} here...}
public void testIntentTriggerViaOnClick() {
buttonId = com.vogella.android.test.simpleactivity.R.id.button1;
Button view = (Button) activity.findViewById(buttonId);
assertNotNull("Button not allowed to be null", view);
view.performClick();
// TouchUtils cannot be used, only allowed in
// InstrumentationTestCase or ActivityInstrumentationTestCase2
// Check the intent which was started
Intent triggeredIntent = getStartedActivityIntent();
assertNotNull("Intent was null", triggeredIntent);
String data = triggeredIntent.getExtras().getString("URL");
assertEquals("Incorrect data passed via the intent",
"http://www.vogella.com", data);
}
}
问题:我的问题是,有没有办法在运行时设置android检测测试用例的顺序,因为我总是看到android测试用例的运行顺序可能相同或者每次都不同,那么我们可以设置任何类型的优先级或运行顺序的顺序吗?。
在上面给出的测试用例代码中,有多个测试用例,每次运行顺序可能与前一个不同,那么我们可以有一个运行顺序的固定顺序吗?
答案 0 :(得分:1)
使用下面的注释
@FixMethodOrder(MethodSorters.NAME_ASCENDING)