Skip to content

Commit

Permalink
Merge pull request #555 from woowacourse-teams/refactor/544-test-perf…
Browse files Browse the repository at this point in the history
…ormance

테스트코드 리팩토링 메인 merge
  • Loading branch information
green-kong authored Oct 10, 2023
2 parents e93ed58 + 82cee80 commit f80eb00
Show file tree
Hide file tree
Showing 35 changed files with 1,558 additions and 1,553 deletions.
6 changes: 4 additions & 2 deletions server/src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
log: &log-option false

spring:
auth:
key: testtesttesttesttesttesttesttesttesttesttesttesttesttesttest
Expand Down Expand Up @@ -33,8 +35,8 @@ spring:
properties:
hibernate:
default_batch_fetch_size: 1000
format_sql: true
show-sql: true
format_sql: *log-option
show-sql: *log-option

s3:
bucket: 2023-team-project/2023-yozm-cafe/test/images

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
package com.project.yozmcafe.controller;

import com.project.yozmcafe.BaseTest;
import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.specification.RequestSpecification;
import static io.restassured.RestAssured.given;
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.documentationConfiguration;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.RestDocumentationExtension;

import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.documentationConfiguration;
import com.project.yozmcafe.BaseTest;
import com.project.yozmcafe.domain.S3Client;
import com.project.yozmcafe.service.auth.JwtTokenProvider;

import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.filter.Filter;
import io.restassured.specification.RequestSpecification;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ExtendWith(RestDocumentationExtension.class)
public abstract class BaseControllerTest extends BaseTest {

@LocalServerPort
private int port;

@SpyBean
protected S3Client s3Client;
@SpyBean
protected JwtTokenProvider jwtTokenProvider;

@Value("${log}")
private boolean showLog;

protected RequestSpecification spec;

@BeforeEach
Expand All @@ -28,4 +45,20 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
this.spec = new RequestSpecBuilder().addFilter(documentationConfiguration(restDocumentation))
.build();
}

protected RequestSpecification customGiven() {
final RequestSpecification customGiven = given();
if (showLog) {
return customGiven.log().all();
}
return customGiven;
}

protected RequestSpecification customGivenWithDocs(Filter document) {
final RequestSpecification customGiven = given(spec).filter(document);
if (showLog) {
return customGiven.log().all();
}
return customGiven;
}
}
Loading

0 comments on commit f80eb00

Please sign in to comment.