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:

junitPlatform {
filters {
engines {
include 'junit-jupiter'
exclude 'junit-vintage'
}
tags {
include 'non-functional'
exclude 'functional'
}
packages {
include 'io.github.bonigarcia'
exclude 'com.others', 'org.others'
}
includeClassNamePattern '.*Spec'
includeClassNamePatterns '.*Test', '.*Tests'
}
}

Notice that we are including the tags non-functional and excluding functional, and therefore we execute four tests:

Gradle execution of test filtering by tags
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.158.134