Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public CustomizeTableEntity(CustomizeTable customizeTable) {
this.consTeamName = customizeTable.getConsTeamName();
this.warningBell = customizeTable.isWarningBell();
this.finishBell = customizeTable.isFinishBell();
this.usedAt = LocalDateTime.now();
this.usedAt = customizeTable.getUsedAt();
Copy link
Contributor

Choose a reason for hiding this comment

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

이건 한번 영속화되었던 거니까 아무래도 벤더와 무관하게 나노초 범위를 똑같이 통일시켜준거군요 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

테스트도 1초 뒤로 설정해서, DB와 무관하게 테스트를 통과하도록 수정했습니다~

}

public CustomizeTable toDomain() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UpdateUsedAt {
void 테이블의_사용_시각을_업데이트한다() {
Member member = new Member("default@gmail.com");
CustomizeTable table = new CustomizeTable(member, "tableName", "agenda", "찬성", "반대",
true, true, LocalDateTime.now().minusNanos(1L));
true, true, LocalDateTime.now().minusSeconds(1L));

Choose a reason for hiding this comment

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

medium

minusSeconds(1L)로 변경하여 시간 정밀도 문제를 해결한 것은 좋은 접근입니다. 다만, 테스트 코드에서 LocalDateTime.now()를 직접 사용하면 테스트가 실행되는 환경이나 시점에 따라 예상치 못하게 실패할 수 있는 비결정적 테스트(flaky test)가 될 수 있습니다. 보다 견고한 테스트를 위해 Clock을 주입하여 시간을 고정하거나, LocalDateTime.of()를 사용하여 특정 시간 값을 명시적으로 사용하는 것을 고려해 보시는 것이 좋습니다.

CustomizeTableEntity customizeTableEntity = new CustomizeTableEntity(table);
LocalDateTime beforeUsedAt = customizeTableEntity.getUsedAt();

Expand Down Expand Up @@ -68,7 +68,7 @@ class Update {
void 테이블_업데이트_할_때_사용_시간을_변경한다() {
Member member = new Member("default@gmail.com");
CustomizeTable table = new CustomizeTable(member, "tableName", "agenda", "찬성", "반대",
true, true, LocalDateTime.now().minusNanos(1L));
true, true, LocalDateTime.now().minusSeconds(1L));

Choose a reason for hiding this comment

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

medium

이 테스트 케이스도 마찬가지로 LocalDateTime.now()를 사용하고 있어 비결정적일 수 있습니다. 테스트의 신뢰도를 높이기 위해 Clock을 사용해 시간을 제어하는 방식을 적용하는 것을 추천합니다. 이렇게 하면 updateTable 메소드 내의 LocalDateTime.now() 호출까지 제어할 수 있어 더욱 안정적인 테스트가 가능해집니다.

CustomizeTableEntity customizeTableEntity = new CustomizeTableEntity(table);
CustomizeTable renewTable = new CustomizeTable(member, "newName", "newAgenda",
"newPros", "newCons", false, false, LocalDateTime.now());
Expand Down
Loading