O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Filtering tests with Gradle

Let's move now to Gradle. As we already know, we can also use Gradle to run JUnit 5 tests. Regarding the filtering process, we can select the test to be executed based on:

  • The test engine: Using the keyword engines we can include or exclude the test engine to be used (that is junit-jupiter or junit-vintage).
  • The Jupiter tags: Using the keyword tags.
  • The Java packages: Using the keyword packages.
  • The class name patterns: Using the keyword includeClassNamePattern.

By default, all engines and tags are included in the test plan. Only the classname containing the word Tests is applied. Let's see a working example. We reuse the same tests presented in the former Maven project, but this time in a Gradle project:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required