添加junit和spring-test還是用不了@Test和@RunWith(SpringJUnit4ClassRunner.class)注解


pom.xml依賴如下

        <!-- spring 單元測試組件包 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.0.7.RELEASE</version>
                        <scope>test</scope>
        </dependency>
 
        <!-- 單元測試Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
                        <scope>test</scope>
        </dependency>

問題解答

  上述scope配置Junit可用的位置test表示只能在src下的test文件夾下面才可以使用

解決辦法

  去掉scope配置就可以

解決后的依賴包修改為如下

        <!-- spring 單元測試組件包 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.0.7.RELEASE</version>
        </dependency>
 
        <!-- 單元測試Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM