首页 > 编程语言 > 详细

Springboot集成Junit

时间:2019-10-08 00:22:47      阅读:105      评论:0      收藏:0      [点我收藏+]

1.新建项目,添加Junit起步依赖.

使用Spring Initializr创建的项目默认已添加该依赖

<!--SpringBoot集成Junit的起步依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

 

2.编写测试类

在test包下,新建com.sui.MybatisTest

package com.sui;

import com.sui.domain.User;
import com.sui.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringbootMybatisApplication.class)
public class MybatisTest {

    @Autowired
    private UserMapper userMapper;

    @Test
    public void test(){
        List<User> users = userMapper.queryUserList();
        System.out.println(users);

    }
}

 

3.运行结果

技术分享图片

 

 

 

 

Springboot集成Junit

原文:https://www.cnblogs.com/jec1999/p/11633080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!