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

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Gradle,
- Task is ambiguous in root project gradle-examples. Candidates are: myTask1, myTask2
- How to create Gradle Multi-Project in IntelliJ
- Find installed Gradle version command
- Adding Jackson dependency to Java Gradle Project
- Gradle FAILURE: Build failed with an exception - Task not found in root project
- Create a Gradle Java Project in VS Code
- Generate Project Dependency tree using Gradle Command
- Fix: Spring Boot + IntelliJ + Gradle : Unsupported class file major version 64 Error
- Fix: Unsupported Java. Your build is currently configured to use Java 17.0.5 and Gradle 7.1.
- Run IntelliJ Java main method without Gradle build
- Fix: Deprecated Gradle features were used in this build, making it incompatible with Gradle
- Installing Gradle on macOS - Gradle Tutorial
- Fix: Invalid Gradle JDK configuration found. Could not find the required JavaSDK
- How to Clear Gradle Cache on Mac
- How to run Gradle build in offline mode
- Install Gradle VS Code for Java Projects
- How to add maven central repository in build.gradle
More Posts:
- Failed to sync Gradle project Error:failed to find target android-23 - Android
- Calculate Area of Trapezoid - C-Program
- How to reset Mac Password using Terminal - MacOS
- Run Scripting Language (JavaScript, Python, Groovy, Ruby) in Java - Java
- Create a large dummy file using Mac OS X terminal command - Mac-OS-X
- How to Install glib on Mac - MacOS
- Change CKEditor Table Properties default width - CKEditor
- Step-by-Step: How to delete a git branch from local as well as remote origin - Git