You may have a lot of Unit Test cases in for your Java Project and might want to run only a single one at a time when either you are testing it or if its the one failing.
In such a case you can run only one test case in one of the following ways.
Option 1: Using the Fully-qualified name for a Class
gradle test --tests "org.code2care.EmployeeTest"
Option 2: Using the Fully-qualified name for a Class and Method
gradle test --tests "org.code2care.EmployeeTest.validUserTest"
Option 3: Using Wildcards *
gradle test --tests "*EmployeeTest.user*"
Read More: https://docs.gradle.org/current/userguide/java_testing.html
Note: If you are using gradle wrapper, make use of gradlew. If you are on Linux/macOS or any other Unix-like operating system, then make use of ./gradlew instead of gradlew.
Option 4: From Multiple Modules
If you have multiple modules, you can run a single test case from a specific module as below,
./gradlew :module_name:test_name

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!