How to run the Spring Boot test class?
The testing class in SpringBoot can be run in several ways.
- Use the run button in the Integrated Development Environment (IDE): Select the test class in the IDE, then click the run button (usually a green triangle), and the IDE will automatically run the test class.
- To run with Maven command: Go to the project’s root directory and type “mvn test” in the command line. This will run all the test classes in the project using Maven.
- To run using the Gradle command, in the project’s root directory, use the command line tool to run the following command: gradle test. This will execute all test classes in the project using Gradle.
- Right-click on the test class, choose “Run As” or “Debug As”, and then select “JUnit Test”. This will use the default JUnit runner to execute the test class.
SpringBoot automatically loads and runs test methods annotated with @Test, and outputs the results regardless of how the test class is executed.