November 2024
Intermediate to advanced
300 pages
7h 12m
English
JUnit 5 lets you mark a test class or a test method with the @Tag annotation. You can use these tags as the basis for running arbitrary sets of tests with JUnit. This is known as filtering your tests.
Let’s take a look at an example. When making changes to the Account class, you should run all tests in both AnAccount and AFundedAccount. You could run all the tests in the package containing both these classes, but you can also use tags to be precise about the subset of tests to run.
Mark both two classes with the @Tag annotation:
| » | import org.junit.jupiter.api.Tag; |
| | import org.junit.jupiter.api.Test; |
| | // ... |
| | |
| » | @Tag("account") |
| | class AnAccount ... |
Read now
Unlock full access