使用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
- 其他參考: