maven-surefire-junit5-tree-reporter icon indicating copy to clipboard operation
maven-surefire-junit5-tree-reporter copied to clipboard

Parameterized tests looks strange

Open alpert opened this issue 2 years ago • 2 comments

Hey, great project!

I have a parameterized test as follows:

@RunWith(JUnitParamsRunner.class)
public class SomeTest {
    @Test
    @Parameters(method = "values")
    public void shouldBeOk(List<Integer> leaderboards, Integer count) {
        assertThat(leaderboards.size(), is(count));
    }
    private Object[] values() {
        return new Object[]{
                new Object[]{List.of(), 0},
                new Object[]{List.of(1), 1},
        };
    }
}

which looks like:

[INFO] ├─ shouldBeOk([], 0) [0] - 0.001s
[INFO] │  ├─ ✔ null - 0s
[INFO] │  └─ ✔ null - 0.001s

To compare: Screenshot 2022-10-26 at 18 58 04

alpert avatar Oct 26 '22 15:10 alpert

Hey, sorry for the delay!

It seems to be related to this library JUnitParams. I think it changes the properties of the tests a little bit and it's causing them to be shown incorrectly.

I'll check if this project is able to support this library or if we have some limitations.

fabriciorby avatar Jan 02 '23 20:01 fabriciorby

I've paired @DisplayName("") with the @ParameterizedTest(name = "") annotations. It appears to be a usable workaround.

Example:

@Test
@DisplayName("Test case for ")
@ParameterizedTest(name = "{0}")
@EnumSource(value = MyTestcase.class)
void shouldTestScenario(MyTestcase myTestcase)

Output is something like this, where VALUE_1 and VALUE_2 are my enum entries:

[INFO] +-- MyTestClass
[INFO] | +-- [OK] Test case for VALUE_1 - 9.132s
[INFO] | +-- [XX] Test case for VALUE_2 - 11.639s

There is one additional problem, though. The Error reporter does not show the @DisplayName or @ParameterizedTest info, so I have no idea which arguments actually failed. This gets hairy for me when I have 20 or so enum values.

Example:

[ERROR] Errors:
[ERROR] MyTestClass.shouldTestScenario(MyTestcase)[2]
[ERROR] Run 1: // omitted
[ERROR] Run 2: // omitted

cksstg avatar Jun 14 '23 23:06 cksstg