Search code examples
javaintellij-ideatestnglogbackmdc

Console output in parallel tests shown in different test tree, than was launched in


I'm using TestNG 6.8.8 in Intellij IDEA 13.4, logback 1.1.2. I have bunch of test classes, and have xml launcher like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Example" parallel="tests" thread-count="3">

<test name="test1">
    <classes>
        <class name="ExampleClass1"/>
    </classes>
</test>
<test name="test2">
    <classes>
        <class name="ExampleClass2"/>
    </classes>
</test>
<test name="test3">
    <classes>
        <class name="ExampleClass3"/>
    </classes>
</test>

also, each class have MDC mark to distinct test classes:

 MDC.put("testName", "ExampleClass1");

and logback.xml:

<configuration>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} %C [%X{testName}]  - %m%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
</appender>

<root level="debug">
    <appender-ref ref="console" />
</root>

</configuration>

when I change xml runner to thread-count="1" everything is fine - console logs each test in it's own tree node.

But when i run TestNG with thread-count="3" or more, some log entries shown not in their own test tree node, but in some others.

for example, console output in tree node for test "test1" can be:

11:53:28.388 ExampleClass1 [ExampleClass1]  - logEntry
11:53:28.388 ExampleClass2 [ExampleClass2]  - logEntry
11:53:29.800 ExampleClass1 [ExampleClass1]  - logEntry2
11:53:29.958 ExampleClass2 [ExampleClass2]  - logEntry2

So, log entry of class ExampleClass2 is shown as result of execution of ExampleClass1, while console output in tree node for test "test2" is empty. also, xml export of console output shows, that some log values goes to different test results.

How Intellij desides for each output line which test is responsible for? Is there any way to enforce Intellij IDEA to somehow check which log entry which class is responsible for by MDC mark? or is there any other way to make sure console output is on it's place in test tree?


Solution

  • It is a known bug. Vote and maybe even bump it.

    IDEA-73260 IntelliJ test runner mixes output from different tests when TestNG parallel is used