新博客:https://blog.bigdataboy.cn/article/452.html
说明
项目地址:https://github.com/junit-team/junit5
添加 maven 依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
创建测试类
@RunWith(SpringJUnit4ClassRunner.class) // 告诉 Junit 执行的 Spring 测试类
@ContextConfiguration(classes = SpringConfig.class) // 注入配置类
public class UserDaoTest {
@Autowired
private UserDao userDao;
@Test
public void testGetUser() {
userDao.getUser();
}
}
测试
需要测试什么类,直接注入
版权声明:《 【Spring】整合第三方框架 之 JUnit 》为明妃原创文章,转载请注明出处!
最后编辑:2022-9-25 13:09:57