默认就集成了Junit的依赖
所以编写一个Test测试类
package com.zbl.service;
import com.zbl.entity.User;
import com.zbl.mapper.UserMapper;
import com.zbl.springboot.SpringbootApplication;
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.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.List;
import static org.junit.Assert.*;
/**
* @Author zhaobaolong
* @Date 2018/8/15 0015
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringbootApplication.class)
public class UserServiceTest {
@Autowired
private UserMapper userMapper;
@Test
public void getUser() {
List<User> user = userMapper.getUser();
System.out.println(user);
}
@Test
public void getOrderById() {
}
}
SpringRunner.class就是以前的Spring4JunitRunner.class的新名字
@SpringBootTest中需要指定你的启动类 ,之后执行测试方法就ok了