skybert
skybert

Reputation: 300

Can't control log4j when running all maven tests

In src/test/resources/log4j.properties I've configured log4j to not log anything.

When I run a single test, i.e. mvn clean test -Dtest=MyTestClass, this log4j properties is heeded. However, when I run all the tests, i.e. mvn clean test, this logging conf is ignored. How can this be?!!

I think I'm going crazy but hope there's a logical explanation :-)

Any help is highly appreciated.

$  mvn -version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk-8-oracle-x64/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.6.0-1-amd64", arch: "amd64", family: "unix"

The sure fire version is 2.19.1:

[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ common-util ---

The src/test/resources/log4j.properties:

log4j.rootLogger=OFF

POM fragments related to resources:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-resources-plugin</artifactId>
      <version>2.5</version>
      <configuration>
        <encoding>ISO-8859-1</encoding>
      </configuration>
    </plugin>

Upvotes: 5

Views: 487

Answers (1)

skybert
skybert

Reputation: 300

One of the 52 test classes under src/test/java had the following lines in its @Before method:

   import org.apache.log4j.BasicConfigurator;

   @Before
   public void setUp() {
     BasicConfigurator.resetConfiguration();
     BasicConfigurator.configure();
   }

For some reason, what must be a bug as far as I can tell, these calls to log4j affects all other junit classes too. Removing these lines made mvn test got the same logging behaviour as running mvn test -Dtest=MyTestClass, i.e. what was defined in src/test/resources/log4j.properties.

Upvotes: 2

Related Questions