1

I have some test classes and methods which running parallel. I'm using log4j2 for logging, however the log outputs to the console is messed up with each other.

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

@Execution(ExecutionMode.CONCURRENT)
public class TestClass1 {
    Logger log = LogManager.getLogger();


    @Test
    public void test1() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("Performing test1 method in " + this.getClass().getName());
    }

    @Test
    public  void test2() {
        log.info("Performing test2 method in " + this.getClass().getName());
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

The expected to see output in test1 TestClass1 - Performing test1 method in TestClass1

and in tests2 TestClass1 - Performing test2 method in TestClass1

Current state: Both outputs printed in first or second test together or only one tests printed. enter image description here enter image description here

natanbig
  • 79
  • 1
  • 1
  • 5

2 Answers2

0

It's look like still existing issue on IntelliJ IDEA IntelliJ test runner mixes output from different tests when TestNG parallel is used

natanbig
  • 79
  • 1
  • 1
  • 5
0

Regarding to opened bug in JetBrains the issue will not be fixed someday. I tried to use TestReporter injection mentioned in bug below, however it also doesn't work.

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestReporter;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

@Execution(ExecutionMode.CONCURRENT)
public class TestClass1 {

    @Test
    public void test1(TestReporter testReporter) {
        testReporter.publishEntry("test1 started");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }

    @Test
    public void test2(TestReporter testReporter1) {
        testReporter1.publishEntry("test2 started");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}

enter image description here

natanbig
  • 79
  • 1
  • 1
  • 5