Maven - 即使添加了依赖项,包org.junit也不存在

时间:2013-03-10 16:06:08

标签: java maven junit

我正在为我的maven项目创建测试类,但maven无法导入JUnit,任何想法为什么?

class Recipebook / src / test / java / RecipebookTest.java:

 import org.junit.Test;
 import org.junit.Before;

 /**
  *
  * @author Mimo
  */
 public class RecipebookTest {
     @Before
     protected void setUp() throws Exception {        
     }
 }

我的pom.xml文件:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <groupId>fi.muni</groupId>
   <artifactId>Recipebook</artifactId>
   <version>2.1.0</version>
   <packaging>jar</packaging>

   <name>Recipebook</name>
   <url>http://maven.apache.org</url>

   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>

   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
     </dependency>
   </dependencies>
 </project>

感谢

1 个答案:

答案 0 :(得分:15)

错误的junit,您需要版本4进行注释。将依赖项更改为:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
</dependency>