Skip to content

Introduce Checkstyle rules to prevent improper use of JUnit APIs in production code #22962

Closed
@sbrannen

Description

@sbrannen

Overview

This issue is a follow up to #22932.

The challenge is to define Checkstyle rules that prevent the use of types such as org.junit.Assert and org.junit.Assume in src/main/java while simultaneously allowing their use in src/test/java.

In addition, the rules cannot be too restrictive since spring-test actually depends on various JUnit APIs.

If we implement such rules, the implementation may require the introduction of a special checkstyle.xml file that is only applied to src/main. Furthermore, we likely should only apply these special rules to spring-test.

In addition, we may want to ensure that we do not accidentally use improper APIs from JUnit Jupiter and TestNG -- for example, their assertion libraries -- in src/main for spring-test.

Deliverables

Introduce Checkstyle rules to prevent improper use of testing/assertion APIs (except where needed in spring-test).

  • JUnit 3: junit.framework.* (src/main and src/test)
  • JUnit 4: org.junit.* (src/main and src/test)
  • JUnit Jupiter:org.junit.jupiter.api.Assertions and org.junit.jupiter.api.Assumptions (src/main and src/test)
  • TestNG: org.testng.* (src/main and src/test)
  • Hamcrest: org.hamcrest.* (src/main and src/test)

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions