ls1intum / Ares

The Artemis Java Test Sandbox. A JUnit 5 Extension for Easy and Secure Artemis Java Testing
https://ls1intum.github.io/Ares/
MIT License
18 stars 7 forks source link

feat: Parameterized Public and Hidden Test annotations #335

Closed justchokingaround closed 7 months ago

justchokingaround commented 7 months ago

I think it would be a good addition to have Parameterized test annotations, since it would allow to avoid helper methods usage / code duplication when testing several different input cases.

I am not sure whether the version numbers are correct.

Here is an example of what it would look like:

public class Numbers {
    public static boolean isOdd(int number) {
        return number % 2 != 0;
    }
}

@ParameterizedPublicTest
@ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) // six numbers
void isOdd_ShouldReturnTrueForOddNumbers(int number) {
    assertTrue(Numbers.isOdd(number));
}

(adapted from https://www.baeldung.com/parameterized-tests-junit-5)

MaisiKoleni commented 7 months ago

First off, thank you for contributing to Ares!

I agree that Ares should work well with parameterized tests. I would, however, like to avoid the approach presented here; otherwise we'd need that for all sorts of test execution annotations. The @PublicTest and @HiddenTest were already a mistake and should instead be @Public @Test and @Hidden @Test. The same goes for parameterized tests.

Have you tried that already? If it didn't work, we should fix that first.

But the code here looks as if it would already work. My suggestion in that case would be to not introduce two new annotations, but simply add integration tests that Ares works well in combination with @ParameterizedTest.

MaisiKoleni commented 7 months ago

Also, I would like to apologize for the late response, I haven't seen much happening here for a long time.

justchokingaround commented 7 months ago

No problem. I have tested it using that approach and it does work. Thank for your response, I didn't know @PublicTest and @HiddenTest were "deprecated".