Skip to content

[java] Possible rules for JUnit5 #2616

@linusjf

Description

@linusjf

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

  1. A rule on the lines of constructor/destructor or constructor/finalize that places @BeforeAll and @BeforeEach methods at the start of the class with @AfterAll and @AfterEach at 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.

  2. An enforcement of the rule that the @BeforeAll and @AfterAll methods either be static or that the class is annotated with @TestInstance(Lifecycle.PER_CLASS).

  3. An enforcement of the @Order annotation so that methods are sorted and presented as per the value specified as a parameter to the annotation.

  4. A rule that recommends that developers declare at most one @BeforeAll and @AfterAll method 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-ruleProposal to add a new built-in rulean:enhancementAn improvement on existing features / rules

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions