简体   繁体   中英

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.

My Tests succeeds running with maven (mvn test) from command line but failing running with Eclipse.

I am using same configuration like JDK, imported in Eclipse as 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:

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.

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. I deleted these and the tests running with success :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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