<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
一个项目中我们会写很多很多测试类,而测试类上面是需要以下几个注解的,每建一个类都去补注解,太麻烦,我们就在这个类中加上注解,其他测试类直接继承这个类就好了
package com.qingfeng.weixi_pay; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest @RunWith(SpringRunner.class) public class WeixiPayApplicationTests { }
package com.qingfeng.weixi_pay.controller; import com.qingfeng.weixi_pay.WeixiPayApplicationTests; import com.qingfeng.weixi_pay.mapper.UserInfoMapper; import com.qingfeng.weixi_pay.model.UserInfo; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; public class TestControllerTest extends WeixiPayApplicationTests { @Autowired private UserInfoMapper userInfoMapper; @Test public void findAll() { UserInfo userInfo = userInfoMapper.selectById(1); System.out.println(userInfo); } }