Skip to content
Advertisement

Loop through array, each element a JUnit test

I have a JUnit 4 test that loops through an array of test data:

JavaScript

Because it’s all in one test method, the whole test stops as soon as one element in the array fails. Is there a way around that, without making a method for each test item? Maybe something with reflection?

Advertisement

Answer

Use JUnit 4’s parameterized tests. They are a perfect fit for this type of problem, although the documentation is quite lacking.

Here are a few other samples on how to use them.:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement