Monday, January 14, 2019

Hello World Parameterized Junit Test

In this article we will see how to build a Parameterized Junit Test.

Parameterized tests was introduced with JUnit 4. Basic concept of Parameterized tests is to run the same test over and over again using different inputs.

There are 4 steps involve in this -

  • Annotate the test class with @RunWith(Parameterized.class)
  • Create a public static method annotated with @Parameterized.Parameters that returns a Collection of Objects as test data set
  • Create a public constructor that takes input as a single data item from step 2
  • Create an instance variable for each item of test data


Lets see the example -

Created a maven project as shown below -


pom.xml

HelloWorld.java

HelloWorldTest.java