First, open your project. What I created is a maven project. It doesn’t matter whether I use maven or not. The method is the same.
Next, find the location shown in the picture below, and then You can start writing your test class
First, you need to create a test class. What I created here is UserTest
Next, you need to import Junit’s jar package. Because I am using maven, I can directly put the coordinates into pom.xml
Next, we can use junit using annotations.
The import package here is import org.junit.Test;
After writing the method, call the specified The method under the class is ready to be tested
Next, call a method under the class that needs to be tested
Next, you can use junit to run the test
The running method selected here is junit. You should not choose other methods to run. Otherwise, the purpose of testing cannot be achieved
Recommended tutorial: Java tutorial
The above is the detailed content of How to test a specified method in java. For more information, please follow other related articles on the PHP Chinese website!