Parameterized tests in JUnit can be very useful when writing tests based on tabular data. These type of tests can save you from writing a lot of duplicate or boilerplate code. While there is a fair amount of articles on the subject on the Internet, I wasn’t able to find a code sample that you can simply copy into your project and execute. So, here it goes.
A Few Notes
@Parameterized.Parameters annotation is available sin JUnit 4.11 and it is used to generate more readable test titles your IDE will display when executing tests. This makes it easier to see what test case failed without looking into the detailed test trace.
It seems that this version is still not propagated in Maven repositories, so I added 4.11-beta-1 version of JUnit as a Maven dependency in order to get all of this working. If you are using some earlier version of JUnit, you simply eliminate the annotation. If you would still like to improve on how the test title is reported, you can take a look at few alternatives proposed in this Stackoverflow question: