How to run a single testng test using gradle command line

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.

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.

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

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. ='myProject'