To have a log4j configuration specific to your tests, for example if your normal log4 configuration write the logs in a file on server for a webapp, do the following:
- create a file src/test/resources/test-log4j.properties containing the configuration of log4j for your tests e.g. :
log4j.rootLogger=DEBUG, R
log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{3}:%L - %m%n - Edit your pom.xml like this:
- <build>
- ...
- <plugins>
- <plugin>
- <artifactid>maven-surefire-plugin</artifactid>
- <version>2.3</version>
- <configuration>
- <systemproperties>
- <property>
- <!-- Specific log4j config for tests -->
- <name>log4j.configuration</name>
- <value>test-log4j.properties</value>
- </property>
- </systemproperties>
- </configuration>
- </plugin>
- ...
- </plugins>
- </build>
- Note: my normal log4j.properties is located in src/main/webapp/WEB-INF/classes/.
0 comments:
Post a Comment