What is TestSuite?

后端 未结 3 597
时光说笑
时光说笑 2020-12-21 00:21

I am relatively new to Java and new to JUnit testing. It\'s absolutely clear to me what the Test class uis, but the TestSuite class confuses me. Ca

3条回答
  •  青春惊慌失措
    2020-12-21 00:48

    Its a collection of tests. It allows you to run such a collection as a group.

    Example from the first link I found with google.

    import junit.framework.Test;
    import junit.framework.TestSuite;
    
    public class EcommerceTestSuite {
    
        public static Test suite() {
    
            TestSuite suite = new TestSuite();
    
            //
            // The ShoppingCartTest we created above.
            //
            suite.addTestSuite(ShoppingCartTest.class);
    
            //
            // Another example test suite of tests.
            // 
            suite.addTest(CreditCardTestSuite.suite());
    
            //
            // Add more tests here
            //
    
            return suite;
        }
    
        /**
         * Runs the test suite using the textual runner.
         */
        public static void main(String[] args) {
            junit.textui.TestRunner.run(suite());
        }
    }
    

提交回复
热议问题