【Spring】整合第三方框架 之 JUnit

新博客: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();
    }
}

测试

需要测试什么类,直接注入

mark

案例代码:https://pan.bigdataboy.cn/s/eXKC4

发表评论 / Comment

用心评论~