How to run a single testng test using gradle command line

Learn
1 min readSep 23, 2023

I did a change in a test, and wanted to run just that one test from that one test file.

./gradlew <projectname>:<subprojectname>:test --tests com.mypackage.MyTestClassName.testForMyCurrentChange

Let us look at that closer.

test
This is the gradle task that actually runs the test.

— tests
This is the parameter to the test task that lets you fine tune the test task and indicate which class, and which method to run.

That should have been sufficient for the use case. The reason it was not was because it is a multi-module project. So, the command tried to run my test against each of the modules in the project, and complained that it could not find any tests matching the command for the modules that the test was not a part of.

<projectname>:<subprojectname>:test
That is where the test target got better qualified with the project and subproject name as “myproject:mymodule:test”.

settings.gradle
This is the file where the modules are defined. Module defined as in matching the module name to the sub-folder with the source for the module.

rootProject.name ='myProject'
include(':myModuleOne')
include(':myModuleTwo')
project(':myModuleOne').projectDir=file('rootFolder/moduleOneFolder')
project(:myModuleTwo').projectDir=file('rootFolder/moduleTwoFolder')

--

--