ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [내일배움캠프] 2월 23일 목요일 TIL 회고록
    카테고리 없음 2023. 2. 23. 23:54

    테스트 코드를 작성했다.

    어려운 부분들은 제외하고 쉬운 부분들만 우선 작성했다..

     

    먼저 boardId와 userId로 댓글이 있는지 확인하는 기능에 대한 테스트 코드를 작성했다.

    @Test
    void existsCommentByBoardIdAndUserId() {
      // given
      Long boardId = 1L;
      Long userId = 1L;
      // when
      commentService.existsCommentByBoardIdAndUserId(boardId, userId);
      // then
      verify(commentRepository, times(1)).existsCommentByBoardIdAndUserId(boardId, userId);
    }

    그 다음 boardId로 댓글이 있는지 확인하는 기능에 대한 테스트 코드를 작성했다.

    @Test
    void existsCommentsByBoardId() {
      // given
      Long boardId = 1L;
      // when
      commentService.existsCommentsByBoardId(boardId);
      // then
      verify(commentRepository, times(1)).existsCommentsByBoardId(boardId);
    }

    댓글 좋아요 서비스단에서 좋아요 취소 기능을 만들었는데 익셉션이 난다..

    @Test
    @DisplayName("좋아요 취소")
    void cancelCommentLike() {
      // given
      Long commentId = 1L;
      Long userId = 1L;
      // when
      commentLikeService.isExistLikesCommentIdAndUserId(commentId, userId);
      commentLikeService.cancelCommentLike(commentId, userId);
      // then
      verify(commentLikeRepository).delete(any(CommentLike.class));
    }

     

    아마 여기에서 문제가 나는 것 같다. 좋아요가 눌렸는지 안눌렸는지 확인하는 기능인데 테스트 코드를 보면 좋아요가 안눌려진 상태라서 익셉션이 출력되는 것 같다. 내일 고쳐봐야겠다.

    commentLikeService.isExistLikesCommentIdAndUserId(commentId, userId);
Designed by Tistory.