springboot 編寫test測試類
阿新 • • 發佈:2021-12-07
匯入依賴
<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-testartifactId> <scope>testscope> dependency> <dependency> <groupId>junitgroupId><artifactId>junitartifactId> <scope>testscope> dependency>
寫測試類
@RunWith(SpringRunner.class) @SpringBootTest(classes = {com.etc.business.EtcBusinessApplication.class}, properties = {"application.properties"}) public class Test { @Test publicvoid test() { } }
注意:
EtcBusinessApplication.class為專案主程式啟動類
測試類啟動,會正常啟動專案,載入專案啟動配置,如果在test資料夾下編寫測試類,建議直接把配置檔案複製到tests檔案下的resource資源目錄下,以免出現啟動時因配置報錯。
詳細參考:https://blog.csdn.net/swadian2008/article/details/95227478