From c7c3d822d94db058b8b2bb9f89ab8438a993c3c9 Mon Sep 17 00:00:00 2001 From: eugenp Date: Fri, 24 Feb 2017 18:04:53 +0200 Subject: [PATCH] testing work with JUnit 5 --- .../src/main/resources/application.properties | 4 ++- .../com/baeldung/IntegrationTestExample1.java | 29 +++++++++++++++++++ .../com/baeldung/IntegrationTestExample2.java | 29 +++++++++++++++++++ .../com/baeldung/ParallelTestExample.java | 24 +++++++++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 spring-5/src/test/java/com/baeldung/IntegrationTestExample1.java create mode 100644 spring-5/src/test/java/com/baeldung/IntegrationTestExample2.java create mode 100644 spring-5/src/test/java/com/baeldung/ParallelTestExample.java diff --git a/spring-5/src/main/resources/application.properties b/spring-5/src/main/resources/application.properties index 2e33b98523..886ea1978b 100644 --- a/spring-5/src/main/resources/application.properties +++ b/spring-5/src/main/resources/application.properties @@ -1,4 +1,6 @@ server.port=8081 security.user.name=user -security.user.password=pass \ No newline at end of file +security.user.password=pass + +logging.level.root=INFO \ No newline at end of file diff --git a/spring-5/src/test/java/com/baeldung/IntegrationTestExample1.java b/spring-5/src/test/java/com/baeldung/IntegrationTestExample1.java new file mode 100644 index 0000000000..0a27be4a95 --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/IntegrationTestExample1.java @@ -0,0 +1,29 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class IntegrationTestExample1 { + + @Test + public void test1a() { + block(3000); + } + + @Test + public void test1b() { + block(3000); + } + + public static void block(long ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + System.out.println("Thread interrupted"); + } + } +} diff --git a/spring-5/src/test/java/com/baeldung/IntegrationTestExample2.java b/spring-5/src/test/java/com/baeldung/IntegrationTestExample2.java new file mode 100644 index 0000000000..0bb2d47ef5 --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/IntegrationTestExample2.java @@ -0,0 +1,29 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class IntegrationTestExample2 { + + @Test + public void test1a() { + block(3000); + } + + @Test + public void test1b() { + block(3000); + } + + public static void block(long ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + System.out.println("Thread Interrupted"); + } + } +} diff --git a/spring-5/src/test/java/com/baeldung/ParallelTestExample.java b/spring-5/src/test/java/com/baeldung/ParallelTestExample.java new file mode 100644 index 0000000000..e73b8d4649 --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/ParallelTestExample.java @@ -0,0 +1,24 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.experimental.ParallelComputer; +import org.junit.runner.Computer; +import org.junit.runner.JUnitCore; + +public class ParallelTestExample { + + @Test + public void runTests() { + final Class[] classes = { IntegrationTestExample1.class, IntegrationTestExample2.class }; + + JUnitCore.runClasses(new Computer(), classes); + } + + @Test + public void runTestsInParallel() { + final Class[] classes = { IntegrationTestExample1.class, IntegrationTestExample2.class }; + + JUnitCore.runClasses(new ParallelComputer(true, true), classes); + } + +} \ No newline at end of file