`

Maven测试报告乱码解决方法

阅读更多

项目运行环境:

  IDE: Eclipse Java EE IDE for Web Developers Indigo

  JDK: 1.6 (32位)

  Maven: 3.0.5

  IDE中Maven插件: m2e 1.3.1

 

在运行maven test, 在IDE Console输出的信息中凡是包含中文的信息都出现了乱码。

 

经过分析,原因应该在maven的测试用的plugin没有定义编码。

 

在项目的Maven pom文件中添加plugin,plugins 标签中定义Maven测试(Maven-surefire-plugin)使用的plugin的编码

 

<plugin>
      <!-- Maven执行单元测试的插件 -->
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.12</version>
      <dependencies>
            <dependency>
                  <groupId>org.apache.maven.surefire</groupId>
                  <artifactId>surefire-junit47</artifactId>
                  <version>2.12</version>
            </dependency>
      </dependencies>
      <configuration>	
            <argLine>-Dfile.encoding=UTF-8</argLine>
      </configuration>
</plugin>

 

  如果想输出一个HTML格式的Junit测试报告还可以使用 maven测试报告插件(maven-surefire-report-plugin)。在pom文件中添加plugin,代码如下:

 

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-report-plugin</artifactId>
	<version>2.14</version>
</plugin>

 

要想使用HTML格式的Junit测试报告,使用Maven 命令 mvn surefire-report:report

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics