添加附加测试后,应使用
@ActiveProfiles
,我得到了异常,这些异常在数据库架构更新时出现。sql脚本在同一数据库上运行了两次。
我使用什么框架
-
spring:3.2.13.Release
&
spring-data-jpa:1.6.5.RELEASE
hsqldb:2.3.2
&
hibernate-entitymanager:4.3.1.FINAL
-
junit:4.12
spring-test:3.2.13.RELEASE
我在代码/测试中使用什么
-
创建我使用的数据源
<jdbc:embedded-database id="dataSource">
.../test/resources/spring/testConfig.xml
-
@RunWith(SpringJUnit4ClassRunner.class)
和
@ContextConfiguration(locations = {"classpath:spring/testConfig.xml"})
为了我的两个测试
-
测试
@活动配置文件
扩展了其他测试<-我查过了,如果这是问题所在
here
,但事实并非如此。
在添加
@活动配置文件
我不想要的
create table exampleModel if not exists
我想要什么
繁殖方式
-
结账
my github-repo
-
跑
mvn test
在里面
./test/
例外
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/testConfig.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to execute database script; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [testDB/schema.sql]: CREATE TYPE TEXT AS VARCHAR(1000000)
...
Caused by: java.sql.SQLSyntaxErrorException: object name already exists: TEXT in statement [CREATE TYPE TEXT AS VARCHAR(1000000)]
...
Caused by: org.hsqldb.HsqlException: object name already exists: TEXT