在网上copy一个spring boot junit的实例,想要测试一下Request请求
http://blog.csdn.net/catoop/article/details/50752964
将url替换成可用地址后, run as -> junit test 发现报错了,log如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
报错的意思是database没有配置好,database type为NONE。但实际上我的spring boot是可以启动,通过浏览器也是可以访问controller获取正确数据的。所以推断肯定是spring boot junit配置有问题。
然后又找了下资料发现
http://blog.csdn.net/u014695188/article/details/52262895
@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes=Application.class)// 指定spring-boot的启动类 //@SpringApplicationConfiguration(classes = Application.class)// 1.4.0 前版本 public class SpringBootJdbcTest {
检查了下我的springboot版本是1.5.3。而junit 里的配置为
@WebAppConfiguration
@ContextConfiguration(classes = Application.class)
public class ControllerTest {
果断将SpringApplicationConfiguration 和WebAppConfiguration 替换为SpringBootTest
再跑,不再报错,测试通过。
再进一步查了下原因发现
@SpringBootTest 会配置spring boot环境而@ContextConfiguration 只会配置spring环境。
相关推荐
windows下eclipse跑junit报错:CreateProcess error=206后面跟着乱码。 把这个jar替换掉就好了,放在:eclipse/plugins/下面。 参考:https://bugs.eclipse.org/bugs/show_bug.cgi?id=327193
由于很多人不会配置Junit4和spring boot集成,所以文档主要讲解spring boot Junit4配置
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2292739
SpringBootJunit5Sample Spring Boot 1.5.10 JUNIT5
1.30 Spring Boot Junit单元测试 1.31 SpringBoot启动时的Banner设置 1.32 Spring boot 文件上传(多文件上传) 1.33 导入时如何定制spring-boot依赖项的版本 1.34 Spring Boot导入XML配置 1.35 Spring Boot使用@...
使用JUnit 5的Spring Boot 一个框架项目,显示应如何配置Spring Boot项目以使用JUnit5。在撰写本文时,Spring Boot Starter Test引入了JUnit(即JUnit 4)而不是JUnit 5(即 )。 来源 您也可以创建此项目! 使用...
主要介绍了Spring Boot通过Junit实现单元测试过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
struts2_spring3.0_Junit4.7_Maven2.2.1_整合运行说明_培训
使用 Spring Boot 的优势 使用 Spring Boot 开发项目,会给我们带来非常美妙的开发体验,可以从以下几个方面展开来说明 Spring Boot 让开发变得更简单 Spring Boot 对开发效率的提升是全方位的,我们可以简单做一下...
struts-junit spring-mock spring-test junit等的javadoc.jar格式的API文档,直接导入Eclipse/MyEclipse/Netbeans等IDE即可实现快速API查询。 包含以下文件: File name -------------------------------------- ...
Spring Boot 2 + JUnit 5示例应用程序1.将JUnit 5依赖项添加到pom.xml < dependency>< groupId>org.junit.jupiter</ groupId>< artifactId>junit-jupiter-api</ artifactId>< scope>test</ scope></ dependency>...
junit4单元测试使用步骤 参数化单元测试示例 spring集成junit4示例
2. 用来加载的Spring的上下文环境 3. 正常的测试类的形式和实现 4. Junit中出现的问题汇总 5. 使用Mock完成单元测试 6. 相关代码参考
spring4+junit4.8 +多线程TheadTool
免费了,spring4+JUnit简单测试,注解组件扫描和xml显示组件扫描,我自己都忘了里面有什么了。
这是一个示例Java 8 / Gradle / PostgreSQL / Spring Boot / REST / JUnit应用程序 要求: Java平台(JDK)8, PostgreSQL JUnit 5 Gradle6.0.1 数据库 创建和配置数据库, url, username, password可以在...
spring AOP及JUNIT包 com.springsource.net.sf.cglib-2.2.0,aopalliance.jar junit4.4.jar aspectj.rar
Use Spring Boot Test framework with JUnit, Cucumber, and Spock Configure and tune web applications and containers Deploy Spring Boot as self-starting executables and Docker containers Monitor data ...
Spring3+junit的单元测试的代码示例。
JUnit大合集,包含你所需的各种文档。