Home » Java » Junit4 - the use of test suites and parametric tes...

Junit4 - the use of test suites and parametric testing

First, the test suite



@RunWith (Suite.class) / * makes a class a class entrance test suite.
@Suite.SuiteClasses ({TaskTest1.class, TaskTest2.class, TaskTest3.class})
Public, class, SuitTest {
*
* 1, the test suite runs together with the organization test class
*
* write an entry class as a test suite that does not contain any other methods
* change the test operator Suite.class
* the class to be tested is passed into the Suite.SuiteClasses as an array
* * /
}








Two, parametric testing



@RunWith (Parameterized.class)
Public, class, ParamsTest {
*
* 1, change the default test tester
* 2, declare variables to store expected values and result values
* 3, declare a common static method that returns Collection, and use @Parameters to modify it
* 4, declare a public constructor with arguments for the test class and assign values for the variables in it
* * /
Int expected=0;
Int input1=0;
Int input2=0;
@Parameters
Public, static, Collection, t () {
Return Arrays.asList (New Object[][]{)
{3,1,2},
{4,2,2},
{2,1,1}
});
}
/*constructor method*/
Public, ParamsTest (int, expected, int, input1, int, input2) {
This.expected=expected;
This.input1=input1;
This.input2=input2;
}
@Test
Public, void, testadd () {
AssertEquals (expected, new, Caculate (),.Add (input1, input2));
}
}











Latest