JUnit Suite Test - JUnit

What is test suit?

Test suite is used to combine a few unit test cases and run them together. In JUnit, both @RunWith and @Suite annotations are used to run the suite tests. Here you can learn by taking two test classes, TestJunit1 & TestJunit2, that run together using Test Suite.

Create a Class

Let’s create a java class to be tested, say, MessageUtil.java in C:\>JUNIT_WORKSPACE.

Create Test Case Classes

Now create a java class file named TestJunit1.java in C:\>JUNIT_WORKSPACE.
Create a java class file named TestJunit2.java in C:\>JUNIT_WORKSPACE.

Create Test Suite Class

  • Create a java class.
  • Attach @RunWith(Suite.class) Annotation with the class.
  • Add reference to JUnit test classes using @Suite.SuiteClasses annotation.
Let’s create a java class file named TestSuite.java in C:\>JUNIT_WORKSPACE to execute test case(s).

Create Test Runner Class

Now create a java class file named TestRunner.java in C:\>JUNIT_WORKSPACE to execute test case(s).
Now compile all the java classes using javac.
Let’s run the Test Runner, as per the predetermined test Case class.
Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JUnit Topics