Springboot單元測試的操作步驟:
1.添加依賴spring-boot-starter-test
在pom.xml中添加依賴spring-boot-starter-test
2.在src/test/java下新建java class
3.單元測試入口代碼結構
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.context.SpringBootTest;@RunWith(SpringRunner.class)
@SpringBootTest(classes =Application.class ) //指定啟動類
public class MyController {@Testpublic void test() {}
}
4.執行
run 單元測試文件
6.執行結果
7.舉例