initializationError JUNIT4

使用spring-boot-starter-test ,在测试发生错误。
错误日志中有这样一句话: Did not detect default resource location for test class

  • 原因:

If you omit both the locations and value attributes from the @ContextConfiguration annotation, the TestContext framework will attempt to detect a default XML resource location. Specifically, GenericXmlContextLoader and GenericXmlWebContextLoader detect a default location based on the name of the test class. If your class is named com.example.MyTest, GenericXmlContextLoader loads your application context from "classpath:com/example/MyTest-context.xml".

  • 简单的来说就是你test 目录有问题,你的test 目录应该与项目的目录一致

  • 当你项目目录为

src/main/java/com/example/demo

  • 你的test目录应该与其一致,应当写成

src/main/test/com/example/demo

  • 其他参考:

https://stackoverflow.com/questions/36622871/spring-integration-testing-could-not-detect-default-resource-locations

你可能感兴趣的:(initializationError JUNIT4)