Spring Boot集成单元测试调用dao,service
1 添加相关依赖
文章来源:https://www.toymoban.com/news/detail-621444.html
<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());
}
}
温馨提示:本人开发上线视频网站,有想要的看视频的,可以看看。小松鼠文章来源地址https://www.toymoban.com/news/detail-621444.html
到了这里,关于Spring Boot集成单元测试调用dao,service的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!