From accedcfb2f9f7c8b3cee602a5f44967483fd9298 Mon Sep 17 00:00:00 2001 From: songhyeonpk Date: Tue, 1 Jul 2025 23:50:35 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9?= =?UTF-8?q?=20Base=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B0=8F=20=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=ED=94=8C=EB=A1=9C=EC=9A=B0=20.env=20=EA=B5=AC?= =?UTF-8?q?=EC=84=B1(#17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 통합 테스트 Base 클래스 추가 * chore: 단위 테스트 Base 클래스 추가 * chore: develop PR 워크플로우에 .env 파일 생성 스텝 추가 --- .github/workflows/develop_pull_request.yml | 4 ++++ .../ject/studytrip/BaseIntegrationTest.java | 23 +++++++++++++++++++ .../java/com/ject/studytrip/BaseUnitTest.java | 11 +++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/test/java/com/ject/studytrip/BaseIntegrationTest.java create mode 100644 src/test/java/com/ject/studytrip/BaseUnitTest.java diff --git a/.github/workflows/develop_pull_request.yml b/.github/workflows/develop_pull_request.yml index 1af5919..7d8e2cc 100644 --- a/.github/workflows/develop_pull_request.yml +++ b/.github/workflows/develop_pull_request.yml @@ -43,6 +43,10 @@ jobs: -p 6379:6379 \ redis:7.0 + - name: Setup .env + run: | + echo "${{ secrets.TEST_ENV }}" >> .env + - name: Grant Execute Permission for Gradlew run: chmod +x ./gradlew diff --git a/src/test/java/com/ject/studytrip/BaseIntegrationTest.java b/src/test/java/com/ject/studytrip/BaseIntegrationTest.java new file mode 100644 index 0000000..d975258 --- /dev/null +++ b/src/test/java/com/ject/studytrip/BaseIntegrationTest.java @@ -0,0 +1,23 @@ +package com.ject.studytrip; + +import com.fasterxml.jackson.databind.ObjectMapper; +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.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest(classes = {StudytripApplication.class}) +@ActiveProfiles("test") +@TestPropertySource(locations = "file:.env") +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +@Transactional +@AutoConfigureMockMvc +public abstract class BaseIntegrationTest { + + @Autowired protected MockMvc mockMvc; + @Autowired protected ObjectMapper objectMapper; +} diff --git a/src/test/java/com/ject/studytrip/BaseUnitTest.java b/src/test/java/com/ject/studytrip/BaseUnitTest.java new file mode 100644 index 0000000..09c83e6 --- /dev/null +++ b/src/test/java/com/ject/studytrip/BaseUnitTest.java @@ -0,0 +1,11 @@ +package com.ject.studytrip; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public abstract class BaseUnitTest { + + protected final ObjectMapper objectMapper = new ObjectMapper(); +}