353 total views
If you are a developer working on a multi-module Gradle project, you might know how to build different modules separately but here we will discuss Gradle JUnits.
For a detailed study, you can visit Gradle docs.
Suppose your project structure looks something like below
So to run all the JUnits in a module, you have to build the module using below command
In Gradle build, a module automatically builds its associated test project.
Skipping Gradle JUnits
However, if you want to skip the tests you can do it with below command
./gradlew parent:moduleA:build -x test
Till now it’s all basic Gradle commands and most of the developers are aware of the above commands.
The main purpose of this blog is to look into specific scenarios like below.
Suppose you have a test class FileHandlerTest.java with 3 Gradle Junits methods
Running all tests of a test class
Now you want to run all the test of FileHandlerTest class only, you can do this using below command
./gradlew parent:moduleA:test –tests “com.techdora.FileHandlerTest”
Running a single test method of the test class
But if you want to run only a single test like testFileSize() you can do this using below command
./gradlew parent:moduleA:test –tests “com.techdora.FileHandlerTest.testFileSize”
As you can see all you have to do is to mention a fully qualified path of the test method.
In conclusion, the above commands will be handy in case you have any issue with your IDE or you want to quickly run the JUnit of your module.
Please put a comment for other scenarios that you might have handled and also check my other blog on how to validate XML using Gradle.