首先 我们在pom.xml中注入JUnit工具
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.8.1</version>
    <scope>test</scope>
</dependency>
然后 我们顺便找个地方顺便写个函数
 
 什么都不需要考虑 些就好了
 然后 我们找到 src下的 test下的测试类
 
 我的代码是这样的
package com.example.webdom;
import com.example.webdom.controller.BookController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.Assert.assertEquals;
@RunWith(JUnit4.class)
@SpringBootTest
public class WebDomApplicationTests {
    public WebDomApplicationTests() {
        // 添加公共构造函数
    }
    @Test
    public void contextLoads() {
        BookController bookController = new BookController();
        int result = bookController.add(2, 3);
        assertEquals(5, result);
    }
}
会不一样的是 BookController 类 这个是我写那个需要测试的函数的类
 然后通过这个类 调用需要测试的函数 add
最后 assertEquals进行测试
 然后 我们右键 contextLoads方法运行测试
 
 也是没有任何问题
 
















![2023年中国铝压延产量、销售收入及市场规模分析[图]](https://img-blog.csdnimg.cn/img_convert/3345b57e70a57a130acb62b47d9a76fc.png)


![2023年中国乳胶制品产量、需求量及市场规模分析[图]](https://img-blog.csdnimg.cn/img_convert/e829c59e22c472301c9226ba973f5a2d.png)