Parallel Test Execution for JUnit 5 - refactoring

This commit is contained in:
Mladen Savic 2021-10-18 18:44:47 +02:00
parent 946ff1183f
commit b2c4765cc3
8 changed files with 48 additions and 92 deletions

View File

@ -1,6 +0,0 @@
## JUnit5
This module contains articles about the JUnit 5
### Relevant Articles:

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>junit5</artifactId>
<name>junit5</name>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,21 +0,0 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Test;
public class A_UnitTest {
@Test
public void first() throws Exception{
System.out.println("Test A first() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test A first() end => " + Thread.currentThread().getName());
}
@Test
public void second() throws Exception{
System.out.println("Test A second() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test A second() end => " + Thread.currentThread().getName());
}
}

View File

@ -1,23 +0,0 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
public class B_UnitTest {
@Test
public void first() throws Exception{
System.out.println("Test B first() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test B first() end => " + Thread.currentThread().getName());
}
@Test
public void second() throws Exception{
System.out.println("Test B second() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test B second() end => " + Thread.currentThread().getName());
}
}

View File

@ -0,0 +1,21 @@
package com.baeldung.parallel;
import org.junit.jupiter.api.Test;
public class FirstParallelUnitTest {
@Test
public void first() throws Exception{
System.out.println("FirstParallelUnitTest first() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("FirstParallelUnitTest first() end => " + Thread.currentThread().getName());
}
@Test
public void second() throws Exception{
System.out.println("FirstParallelUnitTest second() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("FirstParallelUnitTest second() end => " + Thread.currentThread().getName());
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.junit5;
package com.baeldung.parallel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@ -8,7 +8,7 @@ import org.junit.jupiter.api.parallel.ResourceLock;
import java.util.ArrayList;
import java.util.List;
public class C_UnitTest {
public class ParallelResourceLockUnitTest {
private List<String> resources;
@ -26,20 +26,20 @@ public class C_UnitTest {
@Test
@ResourceLock(value = "resources")
public void first() throws Exception {
System.out.println("Test C first() start => " + Thread.currentThread().getName());
System.out.println("ParallelResourceLockUnitTest first() start => " + Thread.currentThread().getName());
resources.add("first");
System.out.println(resources);
Thread.sleep(500);
System.out.println("Test C first() end => " + Thread.currentThread().getName());
System.out.println("ParallelResourceLockUnitTest first() end => " + Thread.currentThread().getName());
}
@Test
@ResourceLock(value = "resources")
public void second() throws Exception {
System.out.println("Test C second() start => " + Thread.currentThread().getName());
System.out.println("ParallelResourceLockUnitTest second() start => " + Thread.currentThread().getName());
resources.add("second");
System.out.println(resources);
Thread.sleep(500);
System.out.println("Test C second() end => " + Thread.currentThread().getName());
System.out.println("ParallelResourceLockUnitTest second() end => " + Thread.currentThread().getName());
}
}

View File

@ -0,0 +1,21 @@
package com.baeldung.parallel;
import org.junit.jupiter.api.Test;
public class SecondParallelUnitTest {
@Test
public void first() throws Exception{
System.out.println("SecondParallelUnitTest first() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("SecondParallelUnitTest first() end => " + Thread.currentThread().getName());
}
@Test
public void second() throws Exception{
System.out.println("SecondParallelUnitTest second() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("SecondParallelUnitTest second() end => " + Thread.currentThread().getName());
}
}