1

i am using maven to run my tests. when the test runs, there are a lot of useless (to me for now, at least) messages outputted to the console. my pom.xml has the following plugin configuration.

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

when i run

mvn clean test

i see the a bunch of messages that look like the following.

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

how do i turn these off?

4

2 回答 2

4

here's how i resolved it. the problem was with setting the compilation to verbose (e.g. java -verbose). in my pom.xml, i made

<verbose>true</verbose>

to

<verbose>false</verbose>

in the build/plugins/plugin section of my pom.xml, the following is what i have now.

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

so those "useless" outputs had nothing to do with the surefire plugin, but instead, with the configuration of the compiler plugin.

于 2013-08-07T18:46:43.607 回答
-1

It depends on how these messages are printed from your code. If they are printed with System.out.println() you will likely not be able to suppress them. If LOG4J is used, you can put the following log4j.xml to src/test/resources or your project:

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

I'm using this approach in my project and it works pretty well. However it can depend on whether you have any other log4j.xml in your classpath (for example in src/main/resources). If yes - additional work will be required to make sure log4j picks up right configuration file for unit test environment.

于 2013-08-06T05:43:48.170 回答