Unit Testing with JUnit test suite

A JUnit test suite is a collection of test cases. A Suite is used to bundle multiple test cases together and run them all at once. Note that we consider a test class as a test case.

The example below shows how to create a Junit Test Suite.

public class TestCase1 {
    
    @Test
    public void testPrint1(){
        System.out.println("Executing Test Print 1")
    }

    @Test
    public void testPrint2(){
        System.out.println("Executing Test Print 2")
    }
}
public class TestCase2 {
    
    @Test
    public void testDisplay1(){
        System.out.println("Executing Test Display 1")
    }

    @Test
    public void testDisplay2(){
        System.out.println("Executing Test Display 2")
    }
}
@RunWith(Suite.class)
@SuiteClasses({
   TestCase1.class,
   TestCase2.class
})
public class TestSuite {   
}

The TestSuite class above is a JUnit Suite. It can execute TestCase1 and TestCase2 together. Below is the result on executing the TestSuite.

Executing Test Print 1
Executing Test Print 2
Executing Test Display 1
Executing Test Display 2
RELATED ARTICLES

Grouping Of Tests using JUnit Categories

JUnit provides the developers with an opportunity to group multiple tests into a single category, thus creating the possibility to include or exclude the category during execution of the test case.

View Article

Testing Exception and Timeout with JUnit

Apart from testing positive scenarios, JUnit can also be used to test negative scenarios. It can be used to test scenarios where an exception is expected or a timeout is to be checked.

View Article

Unit Testing with JUnit

JUnit is a popular unit testing framework that helps developers to unit test their source code during the development of a java application. This articles demonstrates a basic JUnit Test Case.

View Article

Testing with Multiple Inputs using Parameterized Runner

JUnit Parameterized Test Runners provides the abiltiy to run the same test over and over again using different set of inputs.

View Article

Introducing JUnit Rule

Junit Rules allows developers to add additional functionalities that can applied to all test methods in a test class. It is similar to the concept of custom test runners but with reduced restrictions.

View Article