Search code examples
unit-testingintellij-ideajunit5parameterized

Unexpected test count in IntelliJ after adding JUnit ParameterizedTest with ValueSource


I have a JUnit test that includes @BeforeEach and @AfterEach methods, initially set up to test a single endpoint. It runs fine, and IntelliJ correctly shows Test Passed: 1 of 1 test.

Now, I need to test an additional endpoint. I converted this test to a parameterized test by adding the following annotations:

@ParameterizedTest
@ValueSource(strings = {"/api1", "/api2"})

The tests pass successfully for both values, but in IntelliJ's test run window, it shows Test Passed: 3 of 3 tests.

Could someone help me understand why it shows 3 tests when it should be only 2?

Thanks!


Solution

  • Answer just from memory - check the Jupiter code if you have evidence that I'm wrong: The individual calls of a parameterized test are subtests of the parameterized test as a whole. So they are counted as 1 (the test itself) + n (for each set of parameters).