Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 705
Kobi Avatar asked Dec 30 '25 21:12

Kobi


2 Answers

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

like image 163
beatngu13 Avatar answered Jan 02 '26 11:01

beatngu13


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:

  • IntelliJ: https://www.jetbrains.com/help/idea/create-tests.html
  • Eclipse: How to create unit tests easily in eclipse
like image 25
pochopsp Avatar answered Jan 02 '26 10:01

pochopsp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!