Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Intellij show logs when running a test method

Suppose I have the following code:

private static final Logger log = LoggerFactory.getLogger( DummyTest.class );
@Test
public void test() {
    log.info("dummy log");
}

When I run the test method test() in Intellij, I didn't get any log in the console output. However, if I run the test via mvn test from commandline, I will get the log. BTW, I use testng.

So, how can I make Intellij to show the log?

like image 790
JBT Avatar asked Nov 14 '14 06:11

JBT


People also ask

How do I get test reports in IntelliJ?

on the Test Runner toolbar. If you haven't run any tests yet, and the tool window with the Test Runner toolbar is not available, press Ctrl+Shift+A and type Import Tests from File . In the dialog that opens, select the . xml file with test results and click Open.

How do I find the event log in IntelliJ?

Notifications tool window has replaced Event Log that existed in earlier versions of the IDE. All notifications and events that occur in IntelliJ IDEA are gathered in the Notifications tool window. You can open the tool window by clicking the corresponding tool window bar on the right side of the editor.

How do I debug test cases in IntelliJ?

Set a breakpoint before you start the application in the debug mode. The various step actions are: Step Over (F8) lets you execute a line of code and move on to the next line. As you step through the code, you'll see the value of the variables next to the code in the editor window.


1 Answers

I had the same problem - no log output at all in console. Taking @wemu's advice, I added the following file to the src/test/resources/ directory of my project, which gave me the debug ouput from both the test code and the classes under test. Note: I'm using log4j2. The file needed will vary according to your logging framework.

log4j.xml:

<?xml version='1.0' encoding='UTF-8'?>
<configuration monitorInterval="30">
    <appenders>
        <Console name='Console' target='SYSTEM_OUT'>
            <PatternLayout pattern='%d{HH:mm:ss.SSS} %p [%t] %c{1.}.%M %m%n' />
        </Console>
    </appenders>
    <loggers>
        <root level='trace'>
            <appender-ref ref='Console' />
        </root>
    </loggers>
</configuration>
like image 63
Jolta Avatar answered Sep 19 '22 03:09

Jolta