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.