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!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- 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
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated - Java
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error - Git
- How to update Python Version on Mac (macOS) - MacOS
- [Android] Sharing Multiple Images to Twitter App from your App - Twitter
- Android : Prevent App for rotation landscape or portrait - Android
- How to know my IP on Mac Ventura 13.0 - MacOS
- How to Enable Dark Mode Theme in Microsoft Teams - Teams
- CentOS Cannot find a valid baseurl for repo base7x86_64 yum - HowTos