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.
gradle test --tests "org.code2care.EmployeeTest"
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,
Facing issues? Have Questions? Post them here! I am happy to answer!
- Run only a Single Unit Test using Gradle
- Run IntelliJ Java main method without Gradle build
- How to force re-download Gradle Dependencies
- How to Run Gradle Build Without Unit Test Cases
- Find installed Gradle version command
- Fix: Invalid Gradle JDK configuration found. Could not find the required JavaSDK
- Generate Project Dependency tree using Gradle Command
- Installing Gradle on macOS - Gradle Tutorial
- Gradle FAILURE: Build failed with an exception - Task not found in root project
- [Fix] ./gradlew: Permission denied
- Force Gradle to use specific Java JDK Version
- [fix] Deprecated gradle features were used in this build, making it incompatible with Gradle X.0
- Create a Gradle Java Project in VS Code
- Install Gradle VS Code for Java Projects
- Fix: Unsupported Java. Your build is currently configured to use Java 17.0.5 and Gradle 7.1.
- How to create Gradle Multi-Project in IntelliJ
- Fix: Spring Boot + IntelliJ + Gradle : Unsupported class file major version 64 Error
- Fix: Error: Could not find or load main class org.gradle.wrapper. GradleWrapperMain
- [fix] bash: gradlew: command not found
- [fix] Execution failed for task :core:compileJava - Could not find tools.jar
- Run Gradle Build without test cases
- How to add maven central repository in build.gradle
- Upgrade Gradle in Android Studio
- Task is ambiguous in root project gradle-examples. Candidates are: myTask1, myTask2
- Fix: Deprecated Gradle features were used in this build, making it incompatible with Gradle
- Plug-in com.android.ide.eclipse.adt was unable to lead class Error - Android
- How to Exit Node Prompt from Mac Terminal - MacOS
- Program 11: Calculate Percentage - 1000+ Python Programs - Python-Programs
- [Docker] Install Python3 on Alpine Linux - Docker
- PowerShell For Each Loop Examples - Powershell
- How to Get or Set SharePoint Document ID _dlc_DocId using PowerShell - SharePoint
- [Fix] Microsoft Store Error Code: 0x803F8001 - Microsoft
- How to URLEncode a Query String in Python - Python