From 0fa01d5ae5ddff7203ee4752083863c23efba586 Mon Sep 17 00:00:00 2001 From: Chinwat K Date: Fri, 22 Mar 2024 20:21:30 +0700 Subject: [PATCH] separate unit & it test --- kbazaar/build.gradle | 62 ++++++++++++++++++- kbazaar/makefile | 5 +- .../kampus/kbazaar/KBazaarApplicationIT.java | 2 + .../kbazaar/product/ProductServiceTest.java | 1 + 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/kbazaar/build.gradle b/kbazaar/build.gradle index 343b7d1..6b2efb2 100644 --- a/kbazaar/build.gradle +++ b/kbazaar/build.gradle @@ -5,6 +5,7 @@ plugins { id 'io.spring.dependency-management' version '1.1.4' id 'org.sonarqube' version '4.4.1.3373' id 'com.diffplug.spotless' version '6.22.0' + id "com.adarshr.test-logger" version "4.0.0" } jacocoTestReport { @@ -57,9 +58,17 @@ dependencies { testImplementation 'com.tngtech.archunit:archunit-junit5:1.2.1' } -tasks.named('test') { - useJUnitPlatform() - include '**/*Test.java' +test { + testLogging.showStandardStreams = true + useJUnitPlatform { + excludeTags 'integration' + } +} + +task("it-test", type: Test) { + useJUnitPlatform { + includeTags 'integration-test' + } } sonar { @@ -69,4 +78,51 @@ sonar { property "sonar.token", System.getenv("SONAR_TOKEN") property "sonar.host.url", System.getenv("SONAR_HOST_URL") } +} + +testlogger { + // pick a theme - mocha, standard, plain, mocha-parallel, standard-parallel or plain-parallel + theme 'mocha' + + // set to false to disable detailed failure logs + showExceptions true + + // set to false to hide stack traces + showStackTraces true + + // set to true to remove any filtering applied to stack traces + showFullStackTraces true + + // set to false to hide exception causes + showCauses true + + // set threshold in milliseconds to highlight slow tests + slowThreshold 2000 + + // displays a breakdown of passes, failures and skips along with total duration + showSummary true + + // set to true to see simple class names + showSimpleNames false + + // set to false to hide passed tests + showPassed true + + // set to false to hide skipped tests + showSkipped true + + // set to false to hide failed tests + showFailed true + + // enable to see standard out and error streams inline with the test results + showStandardStreams false + + // set to false to hide passed standard out and error streams + showPassedStandardStreams true + + // set to false to hide skipped standard out and error streams + showSkippedStandardStreams true + + // set to false to hide failed standard out and error streams + showFailedStandardStreams true } \ No newline at end of file diff --git a/kbazaar/makefile b/kbazaar/makefile index 2e8d7c5..d92d636 100644 --- a/kbazaar/makefile +++ b/kbazaar/makefile @@ -12,7 +12,10 @@ run: ./gradlew bootRun test: - ./gradlew test + ./gradlew clean && ./gradlew test + +it-test: + ./gradlew clean && ./gradlew it-test format: ./gradlew spotlessApply diff --git a/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationIT.java b/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationIT.java index a65cd7b..c71c120 100644 --- a/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationIT.java +++ b/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationIT.java @@ -2,10 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest +@Tag("integration-test") class KBazaarApplicationIT { @Test diff --git a/kbazaar/src/test/java/com/kampus/kbazaar/product/ProductServiceTest.java b/kbazaar/src/test/java/com/kampus/kbazaar/product/ProductServiceTest.java index 9f5af9b..bf69ff4 100644 --- a/kbazaar/src/test/java/com/kampus/kbazaar/product/ProductServiceTest.java +++ b/kbazaar/src/test/java/com/kampus/kbazaar/product/ProductServiceTest.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock;