Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log messages to JUnit console

Sometimes as I'm writing unit tests it's useful to have log messages, and see them when I run the tests, in the JUnit console (I'm using IntelliJ, but I think Eclipse is very similar).

The problem is that System.out.println doesn't work. Does anyone have any tips on how to print log messages to the JUnit console?

like image 751
Otto Avatar asked Jan 12 '12 15:01

Otto


People also ask

How do you log test unit?

ALL: in unit tests you can change the log level of the logger, to verify that when a certain log level is set, certain messages will no longer be logged. For example, if the log level were to be set to WARN, then the FruitLogger should no longer log the message body.

How do you use logger information in Java?

The info() method of a Logger class is used to Log an INFO message. This method is used to forward logs to all the registered output Handler objects. INFO message: Info is for the use of administrators or advanced users.

What is @after in JUnit?

org.junit If you allocate external resources in a Before method you need to release them after the test runs. Annotating a public void method with @After causes that method to be run after the Test method. All @After methods are guaranteed to run even if a Before or Test method throws an exception.


1 Answers

You should select the test in the tree on the left to see its output in the console on the right:

enter image description here

like image 199
CrazyCoder Avatar answered Sep 21 '22 03:09

CrazyCoder