What is Test Suite?
A Test Suite is a grouping unit test cases together and running it. In JUnit, both @RunWith and @Suite annotations are used to run the suite test.
We will show you how to create and run a Suite. We will create two test classes TestOne and TestTwo.
First create a program with class "TestOne" as below:
import org.junit.Test;
public class TestOne {
@Test
public void testcaseOne(){
System.out.println("Hello im in test case one");
}
}
Now Create another program with class "TestTwo" as below:
import org.junit.Test;
public class TestTwo {
@Test
public void testcaseTwo(){
System.out.println("Hello im in test case two");
}
}
Now for Test Suite Create a Java Class called "TestSuite"
Next add @RunWith(Suite.class)
And also Add the reference to Junit test classes using @Suite.SuiteClasses Annotation.
The code should look like below:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestOne.class,TestTwo.class})
public class TestSuite{
}
Now run the Test Suite class as "Run as Test Suite", The output for the below program should look like below:
OutPut:
Hello im in test case one
Hello im in test case two
- ‹ Defining Firefox Profile preferences using Selenium Webdriver
- Why Automation Testing is required? ›
Add new comment