---
title: "maven2中使用junit4"
author: "dcriori"
date: "2010-01-11T14:35:51Z"
tags: []
categories: ["编程语言"]
slug: "maven2-junit4"
draft: false
lastmod: "2010-01-11T14:35:51Z"
id: 567486
url: "https://dcriori.iteye.com/blog/567486"
---

Maven2默认的Junit是3.8.1，因为以前用的一直是Junit4，感觉很不习惯。在google中搜一下，还真找到了Maven的Junit4的插件。http://wiki.unto.net/Maven\_JUnit4\_plugin，不敢独享。  
只要在POM.XML中加入下面的代码。运行mvn test 就可以了。

```
<dependencies>
   <dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>4.0</version>
     <scope>test</scope>
   </dependency>
 </dependencies>
 
 <build>
   <plugins>
     <plugin>
       <artifactId>maven-compiler-plugin</artifactId>
       <configuration>
         <source>1.5</source>
         <target>1.5</target>
       </configuration>
     </plugin>
     <plugin>
       <groupId>net.unto.maven.plugins</groupId>
       <artifactId>maven-junit4-plugin</artifactId>
       <version>1.0-SNAPSHOT</version>
       <executions>
         <execution>
           <phase>test</phase>
           <goals>
             <goal>test</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
   </plugins>
 </build>
 
 <pluginRepositories>
   <pluginRepository>
     <id>unto.net</id>
     <url>http://repository.unto.net/maven/</url>
     <releases>
       <updatePolicy>daily</updatePolicy>
       <checksumPolicy>warn</checksumPolicy>
     </releases>
     <snapshots>
       <updatePolicy>daily</updatePolicy>
       <checksumPolicy>warn</checksumPolicy>
     </snapshots>
   </pluginRepository>
 </pluginRepositories>

转载：http://blog.csdn.net/wfnlibo/archive/2006/11/26/1414754.aspx
```