Junior — Middle
Have you used parameterization when creating tests?
sobes.tech AI
Answer from AI
Yes, test parameterization is a practice where a single test method is run with different sets of input data. In Java, this is conveniently done using frameworks such as JUnit 5.
Example with JUnit 5:
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class MyTests {
@ParameterizedTest
@ValueSource(strings = {"apple", "banana", "cherry"})
void testWithParameters(String fruit) {
assertNotNull(fruit);
// testing logic with different fruit values
}
}
This helps avoid code duplication and covers more scenarios with a single test.