具體報錯如下:
報這個錯可能根你的網絡有關!
在網上搜了不少解決辦法:最後這個解決辦法最好用。
在pom.xml中加入這個依賴:
這是你的測試啓動配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
在這個配置下面追加一個依賴:
<!--這裏是你要加的依賴-->
<dependency>
<!-- this is needed or IntelliJ gives junit.jar or junit-platform-launcher:1.3.2 not found errors -->
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
添加後如下圖:
這時在重新啓動運行測試,就可以成功了!
運行成功如下圖: