run single integration test with gradle
Solution 1
The correct syntax is:
gradle testTaskName -DtestTaskName.single=...
In this case:
gradle integrationTest -DintegrationTest.single=...
Solution 2
Since Gradle 1.10 you can write:
//select specific test method
gradle test --tests org.gradle.SomeTest.someFeature
//select specific test class
gradle test --tests org.gradle.SomeTest
//select all tests from package
gradle test --tests org.gradle.internal*
//select all ui test methods from integration tests by naming convention
gradle test --tests *IntegTest*ui*
//selecting tests from different test tasks
gradle test --tests *UiTest integTest --tests *WebTest*ui
Read more here http://www.gradle.org/docs/1.10/release-notes#executing-specific-tests-from-the-command-line
Solution 3
Just incase anyone is coming here looking for answers. This has been removed in gradle 5.0. Look for test.single
in https://docs.gradle.org/current/userguide/upgrading_version_4.html
If you still wish to use a command line option in this style you should be able to use the --tests
commandline param. See https://docs.gradle.org/current/userguide/java_testing.html#simple_name_pattern
$ ./gradlew integrationTest --tests=MyTest
Related videos on Youtube
Jeff Storey
Updated on July 09, 2022Comments
-
Jeff Storey almost 2 years
I'm trying to run a single integration tests using gradle's
-Dtest.single
flag. I have added another source set,src/integrationTest
and put the tests in there. I have an integration test tasktask integrationTests(type: Test) { dependsOn 'assemble', 'integrationTestClasses' testClassesDir = sourceSets.integrationTest.output.classesDir classpath = sourceSets.integrationTest.runtimeClasspath }
This runs fine, but if I try to run a single test it tells me it cannot find a matching test. I don't want to have to run every integration test each time I am writing a new one. Is there a way to do this?
-
Noel Yap over 10 yearsWhen I try this, I get something like:
$ gradlew -Dtest.single=SingleTest :subproject:test ... :buildSrc:test FAILED FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':test'. Could not find matching test for pattern: SingleTest
-
Peter Niederwieser over 10 yearsPerhaps you don't have a test class with that name?
-
Peter Kahn over 8 yearsI found that -Dtest.single='foo' was ok on linux but failed on win due to the use of ' vs " or nothing. So, those choices may have impacts due to the shell used.
-
Michał Kosmulski about 8 yearsActually, it should be
-DintegrationTest.single=...
(without the "s") -
Jacques Koorts over 7 yearsActually it should be -DintegrationTests.single=... because he named the task 'integrationTests' in his gradle file.
-
Craig Taylor about 4 yearsThe embedded link nor comment mentions if this works for the integrationTest that the OP was asking about.