Java【SpringBoot】——添加测试依赖

在pom.xml添加依赖

1     <dependency>
2             <groupId>org.springframework.boot</groupId>
3             <artifactId>spring-boot-starter-test</artifactId>
4             <scope>test</scope>
5         </dependency>

添加注解和测试方法

 1 @RunWith(SpringJUnit4ClassRunner.class)                      // 告诉测试类使用的测试工具
 2 @SpringBootTest(classes = MySpringBootApplication.class)    // 指定启动器
 3 public class MySpringBootTest {
 4 
 5     @Autowired
 6     private UserMapper userMapper;
 7 
 8     /**
 9      * 请写入测试方法
10      */
11     @Test
12     public void  test (){
13         System.out.println("测试");
14         List<User> users = userMapper.queryUserList();
15         for (User user:users
16              ) {
17             System.out.println(user);
18 
19         }
20     }
21 }

 

posted @ 2022-09-19 07:07  陆陆无为而治者  阅读(577)  评论(0)    收藏  举报