一、問題描述
Springboot項目,使用單元測試,但是本地無法導入@RunWith註解。
然而,pom中又已經加載了
<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>
二、問題原因
後續通過參考資料,發現添加junit依賴即可。可能原因,是spring-boot-starter-test這個依賴在這個版本中沒有junit,所以需要自己添加。
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
三、參考