创建单元测试@Test一直导入失败

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>
创建单元测试@Test一直导入失败,后来发现是

  <scope>test</scope>搞的鬼,把这行删除后正常运行。

这个问题其实因为不熟悉maven文件结构所致.
测试类一般是放在src/test/java,
而不是放在src/main/java下.maven在编译的时候,src/main/java
下是不引用<scope>test</scope>的jar,而编译src/test/java下的测试这会引用<scope>test</scope>的jar

猜你喜欢

转载自blog.csdn.net/ifidieyoung/article/details/80502014