【发布时间】:2021-01-23 16:37:05
【问题描述】:
我有这个测试
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath:some-context-test.xml")
@DirtiesContext
public class SomeClassIT {
...
@Test
public void someTestMethod() {
...
}
...
}
从 IntelliJ IDEA 触发时运行没有问题,但因错误而失败
[ERROR] someTestMethod(x.y.z.SomeClassIT) Time elapsed: 0.001 s <<< ERROR!
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 [META-INF/db.xml]: Invocation of init method
failed; nested exception is org.hibernate.AssertionFailure: AttributeConverter class [class x.y.z.SomeConverter]
registered multiple times
Caused by: org.hibernate.AssertionFailure: AttributeConverter class [class x.y.z.SomeConverter] registered
multiple times
当通过 maven 执行时
mvn verify -DskipITs=false
但是,如果我从 pom.xml 中删除 maven-shade-plugin 配置(项目正在使用它),那么即使通过 maven,测试也会成功执行。
【问题讨论】:
标签: java spring maven integration-testing maven-shade-plugin