Skip to content

Wisoft-Wasabi/wasabi-backend

Repository files navigation

Wasabi : 와이소프트 사람들의 비밀노트

프로젝트 와사비는 한밭대학교 무선 통신 소프트웨어 및 데이터베이스 연구실(이하 WiSoft)의 기술 블로그를 제작하고자 시작하였습니다.

연구실을 소개하기 위한 기존의 연구실 홈페이지와 달리, 이 기술 블로그에서는 연구실 멤버들만 게시글을 작성할 수 있도록 하여 경험을 공유합니다.


Document.


System Architecture.

wasabi-system-architecture


Backend Response Format

{
    "code":      // code
    "message":   // message
    "data": {
                 // data
    },
    "timestamp": // timestamp
}

Backend Test Code Convention

1. BDD 패턴을 이용 : Mockito.when()이 아닌 BDDMockito.given()를 사용한다.

// we use

@Test
void test() {
    // given

    given( ~~~ );

    // when
    // then
}

/* =========== */

// we don't use
@Test
void test() {
    // given
    // when

    when( ~~~ );

    // then
}

2. then절에 사용되는 검증 메서드는 static import 한다.

  • Assertions.assertEquals()를 사용하지 않고, Assertions.assertThat()을 활용할 것
  • SoftAssertions.assertSoftly()는 2개 이상의 결과를 검증할 경우에만 사용할 것
// we use

@Test
void test() {
    // given
    // when
    // then

    assertSoftly(softAssertions -> {
        softAssertions.assertThat( ~~~ ).isEqualTo( ~~~ );
        softAssertions.assertThat( ~~~ ).isEqualTo( ~~~ );
    });
}

/* =========== */

// we don't use
@Test
void test() {
    // given
    // when
    // then

    Assertions.assertEquals( ~~~ );
}

3. 테스트시 필요한 데이터들은 AutoParams를 적극 활용하고, 애너테이션 순서는 중요한 것을 테스트와 가깝게 선언한다.

  • 테스트를 파악하기 쉽게 @DisplayName()을 가장 상단에 작성하자.
  • AutoParams 관련 애너테이션은 @ParameterizedTest, @AutoSource, @Customization 순으로 나열한다.
// we use

@DisplayName("게시글 좋아요 순 정렬 후 조회시, 좋아요가 가장 많은 게시글이 먼저 조회된다.")
@ParameterizedTest
@AutoSource
@Customization(NotSaveBoardCustomization.class)
void read_boards_order_by_likes(
    final Board board1,
    final Board board2,
    final Member member) throws Exception {

    // given
    // when
    // then  
}

/* =========== */

// we don't use
@DisplayName("게시글 좋아요 순 정렬 후 조회시, 좋아요가 가장 많은 게시글이 먼저 조회된다.")
@Test
void read_boards_order_by_likes() throws Exception {
    // given

    // 게시글 생성을 할 회원 생성 및 저장
    // 회원이 작성한 게시글 1 생성 및 저장
    // 회원이 작성한 게시글 2 생성 및 저장
  
    // when
    // then  
}

4. var 키워드 사용처

  • Integration 및 Repository 테스트의 경우에 when 절의 실행 결과는 var 키워드를 사용하고, 변수명은 result로 통일한다.
  • Controller 단위 테스트의 경우에는 request, response에도 가독성을 위해 var 키워드를 적용한다.
// we use

@DisplayName("요청 시 정상적으로 등록되어야 한다.")
@Test
void register_like() throws Exception {

    //given
    final String accessToken = jwtTokenProvider.createAccessToken(1L, "wasabi", Role.GENERAL, false);

    final var request = new RegisterLikeRequest(1L);

    final var response = new RegisterLikeResponse(1L);
    given(likeService.registerLike(any(), any())).willReturn(response);

    //when
    final var result = mockMvc.perform(post("/likes")
        .contentType(APPLICATION_JSON)
        .header("Authorization", "Bearer" + accessToken)
        .content(objectMapper.writeValueAsString(request)));

    //then
    result.andExpect(status().isCreated());
}

/* =========== */

// we don't use
@DisplayName("요청 시 정상적으로 등록되어야 한다.")
@Test
void register_like() throws Exception {

    //given
    final String accessToken = jwtTokenProvider.createAccessToken(1L, "wasabi", Role.GENERAL, false);

    final RegisterLikeRequest request = new RegisterLikeRequest(1L);

    final RegisterLikeResponse response = new RegisterLikeResponse(1L);
    given(likeService.registerLike(any(), any())).willReturn(response);

    //when
    final ResultActions resultActions = mockMvc.perform(post("/likes")
        .contentType(APPLICATION_JSON)
        .header("Authorization", "Bearer" + accessToken)
        .content(objectMapper.writeValueAsString(request)));

    //then
    resultActions.andExpect(status().isCreated());
}

Member.

mgstyle97
Backend
김민기
kukjun
Backend
이국준
Donggwon-Seo
Backend
서동권
2dongyeop
Backend
이동엽
LimSeNa
Frontend
임세나
Choiminseok18
Frontend
최민석
Jinwon-Dev
Backend
윤진원
leeseunghee00
Backend
이승희

Skill.

Front-End

  • Language
    • JavaScript
  • Framework
    • React

Back-End

  • Language
    • Java 17
  • Framework
    • Spring Boot 3.1.0
  • Library
    • Spring Data JPA
    • Querydsl
    • Log4j2
    • AutoParams
    • Junit5
    • Mockito
  • Database
    • Docker
    • MySQL
  • Infrastructure
    • AWS EC2, RDS

Collaboration

  • Figma
  • Notion
  • Jira

About

WiSoft 연구실 기술 블로그

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages