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>