Reputation: 1798
I'm looking for a way to parameterize my test methods. I'm using JUnit and I want to find a way to unit test a couple of methods. With TestNG's DataProvider I can easily do that: I can provide scenarios to test some methods within a test class. With JUnit's Parameterized alternative I can do it, but the scope of it is the whole class, but I need to reduce the scope to one test method. Is there a way for that?
Upvotes: 2
Views: 1135
Reputation: 825
Have you considered JUnit 5? It's got much better support for parameterization, including what you're looking for.
@ParameterizedTest
@ValueSource(strings = { "Hello", "JUnit" })
void test(String word) {
assertNotNull(word);
}
See https://blog.codefx.org/libraries/junit-5-parameterized-tests/
Upvotes: 4