spring boot中集成了junit測試,無需自行安裝junit。
在pom.xml中新增spring中的junit,若之前新增過junit會進行預設會採用spring boot中的junit
org.springframework.bootspring-boot-starter-testtest
在測試類新增@SpringBootTest註解,測試方法新增@Test註解。
需要注意!!!!如果有新增junit,請務必選擇org.junit.jupiter.api.Test的包。否則無法spring裝載的bean
import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest public class Test1 { @Test public void test(){ System.out.println("test"); } }
版权声明:除非特別標注,否則均為網際整理,轉載時請以連結形式注明文章出處。