什么是TestSuite?

Ива*_*вац 4 java junit test-suite

我是Java的新手,也是JUnit测试的新手.这对我来说绝对清楚是什么Test类,但TestSuite班级让我感到困惑.有人可以解释一下TestSuite是为了什么吗?

Pet*_*rey 9

它是一系列测试.它允许您将这样的集合作为一个组运行.

我在谷歌找到的第一个链接示例.

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());
    }
}
Run Code Online (Sandbox Code Playgroud)