Skip to content

Commit 7c41b13

Browse files
committed
Document how to use Checkstyle rules to forbid Jupiter assertions
1 parent 6437024 commit 7c41b13

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

documentation/src/docs/asciidoc/link-attributes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ endif::[]
240240
:API: https://apiguardian-team.github.io/apiguardian/docs/current/api/[@API]
241241
:API_Guardian: https://github.com/apiguardian-team/apiguardian[@API Guardian]
242242
:AssertJ: https://assertj.github.io/doc/[AssertJ]
243+
:Checkstyle: https://checkstyle.sourceforge.io[Checkstyle]
243244
:DiscussionsQA: https://github.com/junit-team/junit-framework/discussions/categories/q-a[Q&A category on GitHub Discussions]
244245
:Hamcrest: https://hamcrest.org/JavaHamcrest/[Hamcrest]
245246
:Jimfs: https://google.github.io/jimfs/[Jimfs]

documentation/src/docs/asciidoc/user-guide/writing-tests.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,32 @@ include::{testDir}/example/HamcrestAssertionsDemo.java[tags=user_guide]
519519
Naturally, legacy tests based on the JUnit 4 programming model can continue using
520520
`org.junit.Assert#assertThat`.
521521

522+
[TIP]
523+
.Excluding Jupiter’s Assertions From a Project’s Classpath
524+
====
525+
If you would like to enforce that all your tests use a certain third-party assertion
526+
library instead of Jupiter's, you can set up a rule using {Checkstyle} or another static
527+
analysis tool that fails the build if Jupiter's `Assertions` class is used.
528+
529+
[source,xml]
530+
----
531+
<?xml version="1.0" encoding="UTF-8"?>
532+
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
533+
<module name="Checker">
534+
<property name="severity" value="error" />
535+
<module name="TreeWalker">
536+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
537+
<property name="id" value="jupiterAssertions"/>
538+
<property name="maximum" value="0"/>
539+
<property name="format" value="org\.junit\.jupiter\.api\.(Assertions|Assumptions)\."/>
540+
<property name="message" value="Jupiter Assertions/Assumptions should not be used in this project. Please use ... instead."/>
541+
<property name="ignoreComments" value="true"/>
542+
</module>
543+
</module>
544+
</module>
545+
----
546+
====
547+
522548
[[writing-tests-assumptions]]
523549
=== Assumptions
524550

0 commit comments

Comments
 (0)