how to create a robotium testsuite?

后端 未结 3 1487
有刺的猬
有刺的猬 2021-01-21 03:49

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

3条回答
  •  礼貌的吻别
    2021-01-21 04:45

    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.

提交回复
热议问题