假设有一个特定于android的测试用例,如下所示,因为android仪器测试用例的运行顺序总是不相同,]
我的问题是,有什么方法可以设置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); } }
Question:
在上面给出的测试用例代码中,有多个测试用例,并且每次运行顺序可能与前一个不同,因此我们可以确定一个固定顺序的运行顺序吗?
假设有一个特定于android的测试用例,如下所示,因为android仪器测试用例的运行顺序始终不相同,公共类MainActivityUnitTest扩展了android ....
使用以下注释@FixMethodOrder(MethodSorters.NAME_ASCENDING)