What is TestSuite?

拜拜、爱过 提交于 2019-12-29 08:47:25

问题


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. Can someone explain me what TestSuite is for?


回答1:


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());
    }
}



回答2:


It is basically a group of tests that you (or someone) define once which you can run with the click of a button. The tests are automatically run and "marked", and if any test fails you are informed of details.




回答3:


there are some good definitions here: http://xunitpatterns.com/Testcase%20Class.html



来源:https://stackoverflow.com/questions/7250257/what-is-testsuite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!