Search code examples
javaunit-testingtestingjunitjunit4

Junit console output to log


I want to know,

How can I get Junit console output to log file?

As example, I have put Assert.equals() methods. I want to know passed method and what are the failed methods also. I tried to find method to do that, but I was unable.


Solution

  • Check the Log4j Java library. It can be configured to output formatted messages to console and external files. Here are some tutorials:

    In the second one see the code with lines:

    ...
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=C:\\log4j-application.log
    ...
    

    This is where you put the path to the output text file.
    Hope this helps.