How to write something to surefire log with JUnit 4
Is it possible to write something from inside the test to surefire-reports/MyClass.txt ? Any kind of logger etc ? There is a Reporter in TestNG:
Reporter.log("Something here");
and the message appears under test method in report. Is there something simi开发者_C百科liar in JUnit
I had luck using log4j in junit with this kind of set up when running in Eclipse or via Hudson. This may not work with the combination of tests/runners/IDEs you are using, as this doesn't work in all cases for me. You might need to adjust the forkMode. You'll also have to hardcode paths.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>never</forkMode>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>file:src/test/resources/log4j.xml</value>
</property>
</systemProperties>
</configuration>
</plugin>
Another might be to use redirectTestOutputToFile to dump stdout to the surefire report file. Haven't used that so no idea if that will work for you either.
精彩评论