springBoot JunitTest的使用以及如何在junit啓動前加載

springBoot JunitTest的使用

@SpringBootTest(classes = {Application.class},webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestExecutionListeners(listeners = {TestListener.class, DependencyInjectionTestExecutionListener.class })
@TestPropertySource(locations = {"file:../config/prop.properties"})
public class Test {

    @Autowired
    private Service Service;

    @Test
    public void test(){
        Service.testMethod("11111111");
    }

}

首先是@TestExecutionListeners 註解,這個註解可以在junit測試開始之前進行設置環境變量或做其他的事情

@TestPropertySource 這個註解可以爲environment加載一些配置文件,這些配置文件必須是properties,使用過程中發現yaml解析不了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章