From 09c920ea303230f4ea03055fc59d31ad8251d1db Mon Sep 17 00:00:00 2001 From: Piotr Kulasek-Szwed Date: Tue, 25 Feb 2020 12:25:07 +0100 Subject: [PATCH] Integration tests should be separated from unit tests #118 Fix Travis CI and SonarCloud integration #119 Separated unit and integration tests execution phases --- .travis.yml | 2 +- src/mokka/pom.xml | 47 +++++++++++++++++++ .../emulator/logs/LogsControllerIT.java} | 12 ++++- .../mokka/endpoint/FileControllerIT.java} | 7 ++- .../impl/DefaultPaymentStatusServiceIT.java} | 4 +- .../ui/payment/PaymentControllerIT.java} | 2 +- .../resources/application-test.properties | 0 .../java/pl/hycom/mokka/AbstractTest.java | 15 ------ src/pom.xml | 28 +++++++++++ 9 files changed, 93 insertions(+), 24 deletions(-) rename src/mokka/src/{test/java/pl/hycom/mokka/emulator/logs/LogsControllerIntegrationTest.java => integration-test/java/pl/hycom/mokka/emulator/logs/LogsControllerIT.java} (90%) rename src/mokka/src/{test/java/pl/hycom/mokka/endpoint/FileControllerTest.java => integration-test/java/pl/hycom/mokka/endpoint/FileControllerIT.java} (85%) rename src/mokka/src/{test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java => integration-test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceIT.java} (94%) rename src/mokka/src/{test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java => integration-test/java/pl/hycom/mokka/ui/payment/PaymentControllerIT.java} (99%) rename src/mokka/src/{test => integration-test}/resources/application-test.properties (100%) delete mode 100644 src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java diff --git a/.travis.yml b/.travis.yml index 78d460b..33c0350 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ addons: before_install: - cd src script: - - mvn verify org.jacoco:jacoco-maven-plugin:prepare-agent sonar:sonar + - mvn clean verify sonar:sonar -Pcoverage cache: directories: - "$HOME/.m2/repository" diff --git a/src/mokka/pom.xml b/src/mokka/pom.xml index 8b2ac2b..f78375e 100644 --- a/src/mokka/pom.xml +++ b/src/mokka/pom.xml @@ -237,6 +237,7 @@ + @@ -282,6 +283,52 @@ + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-test-source + generate-test-sources + + add-test-source + + + + src/integration-test/java + + + + + add-test-resource + generate-test-resources + + add-test-resource + + + + + src/integration-test/resources + + + + + + + org.apache.maven.plugins maven-surefire-plugin diff --git a/src/mokka/src/test/java/pl/hycom/mokka/emulator/logs/LogsControllerIntegrationTest.java b/src/mokka/src/integration-test/java/pl/hycom/mokka/emulator/logs/LogsControllerIT.java similarity index 90% rename from src/mokka/src/test/java/pl/hycom/mokka/emulator/logs/LogsControllerIntegrationTest.java rename to src/mokka/src/integration-test/java/pl/hycom/mokka/emulator/logs/LogsControllerIT.java index 7cacdbb..3007503 100644 --- a/src/mokka/src/test/java/pl/hycom/mokka/emulator/logs/LogsControllerIntegrationTest.java +++ b/src/mokka/src/integration-test/java/pl/hycom/mokka/emulator/logs/LogsControllerIT.java @@ -5,14 +5,16 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import pl.hycom.mokka.AbstractTest; +import pl.hycom.mokka.Application; import pl.hycom.mokka.emulator.logs.model.Log; import java.sql.Timestamp; @@ -25,8 +27,11 @@ * @author Kamil Adamiec (kamil.adamiec@hycom.pl) */ @DirtiesContext +@ActiveProfiles("test") @AutoConfigureMockMvc -public class LogsControllerIntegrationTest extends AbstractTest { +@AutoConfigureTestDatabase +@SpringBootTest(classes = Application.class) +public class LogsControllerIT { private static final String GET_LOGS_URI = "/logs"; @@ -91,3 +96,6 @@ private MockHttpServletRequestBuilder asyncRequest(MockHttpServletRequestBuilder return builder.header("x-requested-with", "XMLHttpRequest"); } } + + + diff --git a/src/mokka/src/test/java/pl/hycom/mokka/endpoint/FileControllerTest.java b/src/mokka/src/integration-test/java/pl/hycom/mokka/endpoint/FileControllerIT.java similarity index 85% rename from src/mokka/src/test/java/pl/hycom/mokka/endpoint/FileControllerTest.java rename to src/mokka/src/integration-test/java/pl/hycom/mokka/endpoint/FileControllerIT.java index d4ef0a6..0321467 100644 --- a/src/mokka/src/test/java/pl/hycom/mokka/endpoint/FileControllerTest.java +++ b/src/mokka/src/integration-test/java/pl/hycom/mokka/endpoint/FileControllerIT.java @@ -5,10 +5,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.test.annotation.DirtiesContext; -import pl.hycom.mokka.AbstractTest; +import org.springframework.test.context.ActiveProfiles; import static io.restassured.RestAssured.expect; @@ -17,8 +18,10 @@ * @author Mariusz Krysztofowicz (mariusz.krysztofowicz@hycom.pl) */ @DirtiesContext +@ActiveProfiles("test") +@AutoConfigureTestDatabase @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) -public class FileControllerTest extends AbstractTest { +public class FileControllerIT { @Value("${local.server.port}") protected int serverPort; diff --git a/src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java b/src/mokka/src/integration-test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceIT.java similarity index 94% rename from src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java rename to src/mokka/src/integration-test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceIT.java index 5987dcf..8dc2fbf 100644 --- a/src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java +++ b/src/mokka/src/integration-test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceIT.java @@ -1,13 +1,11 @@ package pl.hycom.mokka.service.impl; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.web.client.MockRestServiceServer; import pl.hycom.mokka.service.payment.DefaultPaymentStatusService; import pl.hycom.mokka.service.payment.pojo.BlueMediaPayment; @@ -21,7 +19,7 @@ */ @RestClientTest(DefaultPaymentStatusService.class) @ActiveProfiles("test") -public class DefaultPaymentStatusServiceTest{ +public class DefaultPaymentStatusServiceIT { @Autowired private DefaultPaymentStatusService defaultPaymentStatusService; diff --git a/src/mokka/src/test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java b/src/mokka/src/integration-test/java/pl/hycom/mokka/ui/payment/PaymentControllerIT.java similarity index 99% rename from src/mokka/src/test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java rename to src/mokka/src/integration-test/java/pl/hycom/mokka/ui/payment/PaymentControllerIT.java index 998de5d..a6ab171 100644 --- a/src/mokka/src/test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java +++ b/src/mokka/src/integration-test/java/pl/hycom/mokka/ui/payment/PaymentControllerIT.java @@ -30,7 +30,7 @@ */ @WebMvcTest(PaymentController.class) @ActiveProfiles("test") -public class PaymentControllerTest { +public class PaymentControllerIT { private static final String REDIRECT = "redirect:"; diff --git a/src/mokka/src/test/resources/application-test.properties b/src/mokka/src/integration-test/resources/application-test.properties similarity index 100% rename from src/mokka/src/test/resources/application-test.properties rename to src/mokka/src/integration-test/resources/application-test.properties diff --git a/src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java b/src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java deleted file mode 100644 index 59843d5..0000000 --- a/src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package pl.hycom.mokka; - -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; - -/** - * @author Mariusz Krysztofowicz (mariusz.krysztofowicz@hycom.pl) - */ -@SpringBootTest(classes = Application.class) -@AutoConfigureTestDatabase -@ActiveProfiles("test") -public abstract class AbstractTest { - -} diff --git a/src/pom.xml b/src/pom.xml index 85bd302..4aadbf5 100644 --- a/src/pom.xml +++ b/src/pom.xml @@ -25,4 +25,32 @@ 1.8 + + + coverage + + + + org.jacoco + jacoco-maven-plugin + 0.8.5 + + + prepare-agent + + prepare-agent + + + + report + + report + + + + + + + +