SpringBoot單元測試,無法導入@RunWith

一、問題描述

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>

三、參考

1.https://blog.csdn.net/qq_42734859/article/details/85244556?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

 

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