文章目录
- Spring Boot集成单元测试调用dao,service
- 1 添加相关依赖
- 2 新建测试类
Spring Boot集成单元测试调用dao,service
1 添加相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
2 新建测试类
import com.geekmice.staging.staging.BaoProjectApiApplication;
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;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=Application.class)
// Application 主启动类
public class JzrTest{
@Autowired
private UserDAO userdao;
@Test
//@Commit
//@Transactional
public void test(){
System.out.println(userdao.select());
}
}
温馨提示:本人开发上线视频网站,有想要的看视频的,可以看看。小松鼠