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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容