简体   繁体   English

使用Eclipse和Maven运行SpringBoot JUnit-Tests时的结果不同

[英]Different results when running SpringBoot JUnit-Tests with Eclipse and Maven

I got different results when running SpringBoot-based Java Unit Tests in Eclipse and Maven. 在Eclipse和Maven中运行基于SpringBoot的Java单元测试时,得到了不同的结果。

My Tests succeeds running with maven (mvn test) from command line but failing running with Eclipse. My Tests从命令行成功使用maven(mvn测试)运行,但是在Eclipse中运行失败。

I am using same configuration like JDK, imported in Eclipse as Maven Projekt. 我正在使用与JDK相同的配置,该配置是在Eclipse中作为Maven Projekt导入的。 So almost same settings but does not getting the same results :( 所以几乎相同的设置,但没有得到相同的结果:(

Any tipps how I can solve this problem? 有什么小费我可以解决这个问题吗? Or does have anyone similar issues? 还是有类似的问题?

Most of these are validation exceptions which I am getting when running my tests with eclipse like: 其中大多数是验证异常,使用eclipse运行测试时会遇到这样的异常:

java.lang.Exception: Unexpected exception, expected<com.MyCustomException> but was<javax.validation.UnexpectedTypeException>
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:28)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)

or 要么

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotEmpty' validating type 'java.lang.String'. Check configuration for 'name'
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.throwExceptionForNullValidator(ConstraintTree.java:227)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorNoUnwrapping(ConstraintTree.java:308)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorInstanceForAutomaticUnwrapping ..

But all tests pass with maven. 但是所有测试都通过了Maven。

My Test Class Headers are mostly looking like this: 我的测试班级标题通常如下所示:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:context/service-context.xml" })
@Transactional 
public class SomeFacadeTest { ...}

Thanks 谢谢

Ok, solved my problems ... I had some old external jar lib dependencies under the java build path -> libraries tab view. 好的,解决了我的问题...我在Java构建路径->库选项卡视图下有一些旧的外部jar lib依赖项。 I deleted these and the tests running with success :) 我删除了这些,测试运行成功:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM