Currently I have to create a parameterized test class for every method that I want to test with several different inputs. Is there a way to add this together in one file?
Another pure JUnit but yet elegant solution in my view is to encapsulate each parameterized test(s) in their own inner static class and use the Enclosed test runner on the top level test class. This allows you not only to use different parameter values for each test independently of each other but also to test methods with completely different parameters.
This is how it would look like:
@RunWith(Enclosed.class)
public class CalculatorTest {
@RunWith(Parameterized.class)
public static class AddTest {
@Parameters
public static Collection
Note the usage of the @Parameter annotation in the SubstractTest, which I consider more readable. But this is more a matter of taste.