🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this guide, we'll dive into how to execute tests using Gradle.
Prerequisites
- A Java project set up with Gradle.
- Gradle installed on your machine or the Gradle Wrapper included in your project.
- Some test cases are written (e.g., using JUnit or TestNG) within your project.
Running All Tests
1. Navigate to your project directory
Open your terminal or command prompt and go to the root directory of your Gradle project.
2. Execute the test task
Run the following command:
gradle testIf you're using the Gradle Wrapper (often recommended for consistent builds):
./gradlew testFor Windows:
gradlew.bat testInspecting the Results
By default, Gradle will generate a report once all tests are executed. You can find this report in HTML format at build/reports/tests/test/index.html. Open it in any web browser to view a detailed overview of all executed tests, including those that passed and failed.
Running Specific Tests
If you only want to run a subset of your tests, you can do so using the --tests flag:
gradle test --tests com.example.MyTestClassReplace com.example.MyTestClass with the full name of the test class you want to run. To run specific methods within a test class:
gradle test --tests com.example.MyTestClass.myTestMethodWildcards can also be used:
gradle test --tests com.example.* // will run all tests in the com.example packageContinuous Test Execution
Gradle allows for continuous testing which means it will keep running in the background, watching for changes in your files, and re-run tests when it detects changes. This can be activated using the -t flag:
gradle test -tConclusion
Running tests with Gradle is a breeze. The tool offers flexibility, allowing developers to run all tests, specific tests, or even enable continuous testing. This makes the feedback loop shorter, and errors can be caught early during development. With the test reports generated, one can also get an overview of the project's test health. Always remember that consistent testing leads to more reliable software.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment