Home > Java > JavaBase > body text

How to test a specified method in java

王林
Release: 2019-11-18 15:53:44
Original
3463 people have browsed it

How to test a specified method in java

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.

How to test a specified method in java

Next, find the location shown in the picture below, and then You can start writing your test class

How to test a specified method in java

First, you need to create a test class. What I created here is UserTest

How to test a specified method in java

Next, you need to import Junit’s jar package. Because I am using maven, I can directly put the coordinates into pom.xml

How to test a specified method in java

Next, we can use junit using annotations.

How to test a specified method in java

The import package here is import org.junit.Test;

How to test a specified method in java

After writing the method, call the specified The method under the class is ready to be tested

How to test a specified method in java

Next, call a method under the class that needs to be tested

How to test a specified method in java

Next, you can use junit to run the test

How to test a specified method in java

The running method selected here is junit. You should not choose other methods to run. Otherwise, the purpose of testing cannot be achieved

How to test a specified method in java

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!