-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[java] Possible rules for JUnit5 #2616
Copy link
Copy link
Open
Labels
a:new-ruleProposal to add a new built-in ruleProposal to add a new built-in rulean:enhancementAn improvement on existing features / rulesAn improvement on existing features / rules
Metadata
Metadata
Assignees
Labels
a:new-ruleProposal to add a new built-in ruleProposal to add a new built-in rulean:enhancementAn improvement on existing features / rulesAn improvement on existing features / rules
Type
Fields
Give feedbackNo fields configured for issues without a type.
Is your feature request related to a problem? Please describe.
Having currently tried out JUnit5 for unit tests recently, I have the following suggestions for new rules using the testing harness.
Describe the solution you'd like
A rule on the lines of constructor/destructor or constructor/finalize that places @BeforeAll and
@BeforeEachmethods at the start of the class with@AfterAlland@AfterEachat the end of the class. This could be configurable to have all the methods at the top of the test class if that's preferable instead.An enforcement of the rule that the
@BeforeAlland@AfterAllmethods either be static or that the class is annotated with@TestInstance(Lifecycle.PER_CLASS).An enforcement of the
@Orderannotation so that methods are sorted and presented as per the value specified as a parameter to the annotation.A rule that recommends that developers declare at most one
@BeforeAlland@AfterAllmethod per test class. More than one is to be discouraged.https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/BeforeAll.html
Additional context
The first and fourth rules could be extended to other frameworks.