Reputation: 43
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.
Upvotes: 3
Views: 13916
Reputation: 126
It worked for me:
private void log(String s) {
System.out.println(s);
System.out.flush(); // the magic is here
}
PS: It works for Ant launched from pure console without any IDE. You may have to add more magic like Thread.sleep(1000) for IDEA IDE.
Upvotes: 1
Reputation: 2151
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.
Upvotes: 1
Reputation: 321
If you are using eclipse, you can achieve it by going to Run configuration > Common > Output file> giving path of your log file.
Upvotes: 4