views:

172

answers:

1

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 similiar in JUnit

+2  A: 

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.

sal
Actually I managed to create logger that writes to file in surefire-reports folder. I rather wanted to have one single report file with test results and my log messages. Thanks for help.
peperg