Merge pull request #11271 from mladensavic94/master
Parallel Test Execution for JUnit 5
This commit is contained in:
commit
4dfe21a3dc
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.baeldung.parallel;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.parallel.ResourceLock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ParallelResourceLockUnitTest {
|
||||
|
||||
private List<String> resources;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
resources = new ArrayList<>();
|
||||
resources.add("test");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
resources.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ResourceLock(value = "resources")
|
||||
public void first() throws Exception {
|
||||
System.out.println("ParallelResourceLockUnitTest first() start => " + Thread.currentThread().getName());
|
||||
resources.add("first");
|
||||
System.out.println(resources);
|
||||
Thread.sleep(500);
|
||||
System.out.println("ParallelResourceLockUnitTest first() end => " + Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ResourceLock(value = "resources")
|
||||
public void second() throws Exception {
|
||||
System.out.println("ParallelResourceLockUnitTest second() start => " + Thread.currentThread().getName());
|
||||
resources.add("second");
|
||||
System.out.println(resources);
|
||||
Thread.sleep(500);
|
||||
System.out.println("ParallelResourceLockUnitTest second() end => " + Thread.currentThread().getName());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
junit.jupiter.execution.parallel.enabled = true
|
||||
junit.jupiter.execution.parallel.config.strategy=dynamic
|
||||
junit.jupiter.execution.parallel.mode.default = concurrent
|
||||
junit.jupiter.execution.parallel.mode.classes.default = concurrent
|
Loading…
Reference in New Issue