Manage test suite

Source: Internet
Author: User
Test Suite is the minimum test execution unit of JUnit. 1. Use JUnit to construct test suite: JUnit has a built-in mechanism to construct test suite, as long as the testcase class complies with the following principles:. the test method must be at the instance level. If no parameter is received, void is returned. The declared method is as follows: public void testmethodname () B. the test method must start with test (all in lowercase). By default, the test suite in a testcase includes not only the self-declared test method, it also includes all valid test methods declared in the parent class. 2.Collect specified test cases:. create a suite () method in the testcase class and declare it as public static test suite (). The test object is returned without any parameter B. create a testsuite object in the suite () method body and add the test object to the suite: a single test or other suitepublic Static Test Suite (){
Testsuite suite = new testsuite ();
Suite. addtest (New moneytest ("testmoneyequals "));
Suite. addtest (New moneytest ("testbagequals "));
Suite. addtest (New moneytest ("testsimpleadd "));
Suite. addtest (New moneytest ("testmixedsimpleadd "));
Suite. addtest (New moneytest ("testbagsimpleadd "));
Suite. addtest (New moneytest ("testsimplebagadd "));
Suite. addtest (New moneytest ("testbagbagadd "));
Return suite;
} 3. Collect all the test cases of a package. The difference is that the suite method of testcase is added to the suite instead of a single test. We recommend that each package have an alltests class, collect all the testcase classes under the package according to the above rules, and then establish a system-level alltests class, including the alltests under each package. The alltests class can not be a subclass of testcase public static test suite (){
Testsuite suite = new testsuite ();
Suite. addtestsuite (atestcase. Class );
Suite. addtestsuite (atestsuitecase. Suite (); Return suite;
} 4. Collect all tests of the entire system: Establish a system-level alltests, with 3 5. Scan the file system to find all test cases: A. Use gsbase (http://gsbase.sourceforge.net/) recursivetestsuiteb. Use JUnit-Addons (http://junit-addons.sourceforge.net) for junitx. util. directorysuitebuilder 6.Differentiate different test types (programmer test, customer test, end-to-end test):. create different Project B for different test types. build different source code test branches for the same project: src/test, cactus test: src/testcactusc. implement the specified interface tag. For example, the customer test class implements the customertest interface. 7.Control the execution sequence of some tests: Use orderedtestsuitea of gsbase. add a suite () method B to the test class. create an orderedtestsuite, specify the list of tests to be executed in sequence, and return orderedtestsuitepublic Static Test Suite (){
String [] orderdependenttests = new string [] {
"Testquerywithnoaccounts ",
"Testinsert ",
"Testinsertaccountexists ",
"Testquerywithoneaccount ",
"Testdelete"
};
Return new orderedtestsuite (
Accountdatastoretest. Class, orderdependenttests );
} 8. Construct data-driven test suite: it is suitable to make the input values and expected values different. Other steps are the same.. construct a testxxx () method for verification. input values and expectations use the routine variable B. create a constructor with the input value and expected value saved to the corresponding routine variable C. create the suite () method, construct the testcase, use the constructor with parameters, and add it to the suite. D. execute the suite () method 9.Define test suite in XML file: store the input values and expectations in XML file format, and load the XML file in the suite () method to execute the method in 8, XML files are only one form of data storage. You can select other storage formats, which are not applicable to cactus

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.