Skip to content

Commit

Permalink
test : Integration Test를 도와주는 Supporter 클래스 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
java-saeng committed Apr 24, 2023
1 parent f602eea commit e90197a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/resources/sql/data.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
insert into RACE_RESULT
values (1, 10, current_timestamp);
insert into CAR
values (1, '우르', 9, 1, 1, current_timestamp);
values (1, '우르', 9, 1, 0, current_timestamp);
insert into CAR
values (2, '빙봉', 10, 1, 0, current_timestamp);
values (2, '빙봉', 10, 1, 1, current_timestamp);

insert into RACE_RESULT
values (2, 5, current_timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import racingcar.domain.RacingGame;
import racingcar.support.AbstractIntegrationTestSupporter;
import racingcar.util.RandomNumberGenerator;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

@DisplayName("CarService Integration Test")
@SpringBootTest
class CarServiceIntegrationTest {
class CarServiceIntegrationTest extends AbstractIntegrationTestSupporter {

@Autowired
private CarService carService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
package racingcar.service;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import racingcar.service.dto.CarStatusResponse;
import racingcar.service.dto.GameInfoRequest;
import racingcar.service.dto.RaceResultResponse;
import racingcar.support.AbstractIntegrationTestSupporter;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@DisplayName("RaceResultService Integration Test")
class RaceResultServiceIntegrationTest {
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class RaceResultServiceIntegrationTest extends AbstractIntegrationTestSupporter {

@Autowired
private RaceResultService raceResultService;

@Test
@DisplayName("createRaceResult() : 게임 정보를 통해 새로운 게임을 만들 수 있다.")
@Order(1)
void test_createRaceResult() throws Exception {
//given
final String input = "a,b,c,d";
Expand All @@ -41,6 +48,7 @@ void test_createRaceResult() throws Exception {

@Test
@DisplayName("searchRaceResult() : 모든 경기 결과를 조회할 수 있다.")
@Order(2)
void test_searchRaceResult() throws Exception {
//given
final List<String> winnerResult = List.of("빙봉", "a,b,c,d");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package racingcar.support;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;

@SpringBootTest
@Sql(value = "/sql/schema.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(value = "/sql/data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
public class AbstractIntegrationTestSupporter {
}
3 changes: 3 additions & 0 deletions src/test/resources/sql/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
DROP TABLE IF EXISTS RACE_RESULT;
DROP TABLE IF EXISTS CAR;

CREATE TABLE RACE_RESULT
(
id BIGINT NOT NULL AUTO_INCREMENT,
Expand Down

0 comments on commit e90197a

Please sign in to comment.