@Test annotations on test classes (types) instead on each test method

106 views Asked by At

Is there any @Test-related annotation in the JUnit Jupiter API that allows us to highlight the whole test class as a testing class?

Since each test method needs to be annotated with @Test, this would save some time when writing tests within test classes that do not include non-test methods.

2

There are 2 answers

0
beatngu13 On BEST ANSWER

No, back in 2019 the JUnit team decided against a class-level @Test annotation:

There are many ways to declare tests in Jupiter: @Test, @TestFactory, @TestTemplate (@RepeatedTest, @ParameterizedTest) -- we want them to be explicitly visible and not rely on a pattern that matches a method signature.

https://github.com/junit-team/junit5/issues/1761#issuecomment-466149986

0
pochopsp On

I'm afraid there is not such annotation in JUnit.

Is it really time consuming to add @Test on each method?

Maybe you could use your IDE auto generate tools to generate test methods for you, see for example: