2013-08-06 22 views
1

我正在使用maven来运行我的测试。当测试运行时,对于输出到控制台的消息有很多无用的东西(至少对我来说)。我的pom.xml具有以下插件配置。如何关闭或压缩邮件测试加载邮件

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-surefire-plugin</artifactId> 
<version>2.15</version> 
<configuration> 
    <includes> 
    <include>**/*Tests.java</include> 
    </includes> 
    <systemPropertyVariables> 
    <log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration> 
    </systemPropertyVariables> 
</configuration> 
</plugin> 

当我运行

mvn clean test 

我看到一堆看起来像以下消息。

[parsing started RegularFileObject[...]] 
[search path for source files: ...] 
[search path for class files: ...] 
[loading ZipFileIndexFileObject[...]] 

如何关闭这些功能?

回答

3

这是我解决它的方式。问题在于将编译设置为冗长(例如java -verbose)。在我的pom.xml,我在编译/插件/插件,我的pom.xml的部分由

<verbose>true</verbose> 

<verbose>false</verbose> 

,以下是我现在有。

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<version>3.0</version> 
<configuration> 
    <compilerArguments> 
    <Xlint /> 
    </compilerArguments> 
    <verbose>false</verbose> 
    <source>${java.version}</source> 
    <target>${java.version}</target> 
    <showWarnings>true</showWarnings> 
    </configuration> 
</plugin> 

所以这些“无用”的输出,没有什么做的万无一失插件,而是与编译器插件的配置。

-1

这取决于如何从您的代码打印这些消息。如果它们使用System.out.println()打印,则可能无法抑制它们。如果使用log4j,您可以把以下的log4j.xml的src /测试/资源或您的项目:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" > 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> 
    <appender name="devnull" class="org.apache.log4j.varia.NullAppender"/> 
    <root> 
     <priority value="info"/> 
     <appender-ref ref="devnull"/> 
    </root> 
</log4j:configuration> 

我用这个方法在我的项目,它工作得很好。但是,它可能取决于您的类路径中是否有其他log4j.xml(例如,在src/main/resources中)。如果是 - 将需要额外的工作来确保log4j为单元测试环境选择正确的配置文件。

+0

我没有做任何System.out.print的。它似乎是这些消息是从Maven surefire插件输出,当它扫描类和罐子运行测试。但我必须同意,它们似乎是System.out.print消息,因为它们的输出与log4j.properties或logback.xml中定义的内容不相似。顺便说一下,我试图把这个log4j.xml文件放到我的src/test/resources文件夹中,但这没有帮助。现在我不得不怀疑,如果这是真的,他们为什么要使用System.out.println以及为什么这样看起来毫无用处的消息。 –

+0

好吧,我只是发现那些消息可以由“javac -verbose”生成。我根据http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html关闭了它,现在这些输出消失了。 –

+0

Goot知道你已经解决了它。我认为在这里作出回答并接受它是值得的,所以其他人看到了正确的答案。 –