If multiple test cases are in different classes and you need to execute all the test cases at once, you can use the bulk execution test method in JUnit.
Method One
This is very simple and does not require an extra line of code, and Eclipse would have supported batch execution of tests in project or package units.
Case.
Right-click on the project--->run as--->run configurations.
Click "Search ..." Button.
Select the specified package under Engineering/engineering. Click "OK" to go back to the Run Configuration window and click the "Run" button to run all the test cases under the selected range.
The second Kind
This approach introduces the concept of a "test suite", and JUnit provides a way to run the test class in batches, called a test suite.
The test suite should be written in the following guidelines:
1. Create an empty class as the entrance to the test suite;
2. Use annotations Org.junit.runner.RunWith and org.junit.runners.Suite.SuitClasses to decorate this empty class
3. Pass the Org.junit.runners.Suite as a parameter to the annotation runwith to prompt JUnit to use the suite runner for such tests
Yes.
4. Make an array of the test classes that need to be put into this test suite as parameters for the annotation suiteclasses
5. Ensure that the empty class is decorated with public and that there are exposed constructors with no arguments
Note: suitclasses ({ Here contains the. class file for the class that needs to run the test case})
Below the test package (com.junit.test), create a test class that reads as follows:
Package com.junit.test; Import Org.junit.runner.RunWith; Import Org.junit.runners.Suite; Import org.junit.runners.Suite.SuiteClasses; @RunWith (Suite. class ) @SuiteClasses ({testadd. class , TestSub. class ,}) Public class Testall {}
JAVA Batch Execution test cases