5

我正在为我的 Maven 项目创建测试类,但是 Maven 无法导入 JUnit,有什么想法吗?

类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>

谢谢

4

1 回答 1

15

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

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
</dependency>
于 2013-03-10T16:07:49.530 回答