Skip to content

Conversation

@l-lyun
Copy link
Member

@l-lyun l-lyun commented Nov 13, 2025

작업 사항

테스트 코드 작성

  • 게시글 생성
  • 게시글 수정
  • 게시글 삭제
  • 게시글 검색

@l-lyun l-lyun self-assigned this Nov 13, 2025
Comment on lines +67 to +75
public static void validateString(
String data,
ErrorCode errorCode
) {
if (Strings.isBlank(data)) {
throw new CustomException(errorCode);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이 if절이 가독성을 해치는것 같아 강사님처럼 Preconditions를 만들었는데,

이런 부분에 대해서 컨벤션 만드는게 필요할 것 같습니다.

@junsang-ee @oneokiwa @FA-50

Comment on lines +114 to +154
@ParameterizedTest
@NullAndEmptySource
@DisplayName("게시글 생성 실패 제목 공백")
void 게시글_생성_실패__제목_null_공백(String title) {
UserEntity user = createUser();
BoardEntity board = createBoard(user);

assertThrowsExactly(
CustomException.class,
() -> postService.create(
board.getId(),
new PostRequest.Create(
title,
"content",
PostDisclosureType.PUBLIC,
user.getId()
)
)
);
}

@ParameterizedTest
@NullAndEmptySource
@DisplayName("게시글 생성 실패 내용 공백")
void 게시글_생성_실패__내용_null_공백(String content) {
UserEntity user = createUser();
BoardEntity board = createBoard(user);

assertThrowsExactly(
CustomException.class,
() -> postService.create(
board.getId(),
new PostRequest.Create(
"title",
content,
PostDisclosureType.PUBLIC,
user.getId()
)
)
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떻게 보면 이부분이 도메인 테스트와 겹치는 것 같습니다

}

@Test
@DisplayName("게시글 생성")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메소드마다 @DisplayName 지정해주지 않아도, 메소드 명으로 테스트 결과에서 확인 가능합니다.

assertThat(result.getContent().stream()
.allMatch(post ->
post.title().contains("con") ||
post.content().contains("con"))).isTrue();
Copy link

@tryterry77 tryterry77 Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"con"과 같이 여러 곳에서 비교 대상이 되면서 공통적으로 사용하는 값은 변수로 선언해서 사용하면

테스트 코드 작성할때 실수를 줄일 수 있을것 같습니다.

예) String target = "con" 으로 선언 후 필요한 곳에서 사용

물론 copilot을 사용하면 자동으로 해주긴 하지만요..ㅎㅎ

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견입니다 여러곳에서 쓰인다면 그것도 헷갈리지 않는 방법중에 하나겠네요!

Comment on lines +294 to +296
createPost(user, board);
createPost(user, board);
createPost(user, board);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createPost 는 공통으로 들어가니 BeforeEach 에 미리 init 해주심 더 편할듯 합니다~

// when
postService.remove(post.getId());
// then
assertThat(postRepository.findById(post.getId())).isEmpty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다 근데 not found 에러로 체크해보심도 한번 고려해보십쇼

Comment on lines 58 to 62
BoardEntity boardEntity = boardRepository.save(
BoardEntity.create(
"테스트게시판",
userEntity
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희는 앞으로
BoardEntity board = BoardEntity.create();
하고 난 뒤에 board 객체를 boardRepository.save(board); 에 넣어서 영속성 객체 얻기루 했습니다! 참고하셔요~

)
);
// then
Optional<PostEntity> first = postRepository.findAll().stream().findFirst();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findByName() Optional 메소드를 만들어 보는건 어떨까욤~?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants