Reputation: 1391
I have the following tests classes.
com.baz.bar.Foo
com.bar.foo.Baz
com.foo.baz.Bar
I want to execute com.baz.bar.Foo
and com.bar.foo.Baz
. I know how to execute all of them and how to execute one of them. I don't know how to execute any arbitrary set between.
Upvotes: 33
Views: 14513
Reputation: 76
To execute a set of tests, separate them by ||, e.g:
gradlew tests --tests=Foo||Bar||Baz
Upvotes: 0
Reputation: 4586
This answer is an extension to this
Command line option:
If you want to execute multiple tests which are in different packages from command line, you can execute as follows:
<> --> replace with values
format: [gradle or ./gradlew] <Task name> --tests "<package-name>.<* or class-name>"
gradle test --tests "com.xyz.*" --tests "org.abc.*"
# OR with gradle wrapper
./gradlew test --tests "com.xyz.*" --tests "org.abc.*"
Above command will execute all tests present in package com.xyz
and org.abc
for test
task, same command can be used for other functional and integration tasks as well.
Verified with gradle version 7.4 for java/kotlin project.
Upvotes: 4
Reputation: 748
Gradle supports multiple --tests
statements, i.e:
gradle test --tests com.baz.bar.Foo --tests com.bar.foo.Baz --tests com.foo.baz.Bar
would do what you want
Upvotes: 56
Reputation: 123910
It's easy to do in a build script:
test {
filter {
filterTestsMatching "com.baz.bar.Foo", "com.bar.foo.Baz", ...
}
}
The command line equivalent is gradle test --tests com.baz.bar.Foo
(or just --tests Foo
), but from what I can tell, only a single class (more precisely a single pattern) is supported here.
If you need the ability to pass multiple patterns, you can script this yourself. For example, you could read a system property passed from the command line via -Dtest.filter=Foo,Bar,Baz
, split the value into its individual parts, and feed those into filterTestsMatching
.
Enhancing --tests
to support comma-delimited values might make a good pull request for the Gradle project.
Upvotes: 9