Skip to content

Conversation

@mingimin
Copy link

Board Model 과 Repository 에 한하여 기본 Test 만 작성하였습니다.

Board Model 과 Repository 에 한하여 Test 작성

import java.util.ArrayList;

@Repository
Copy link
Member

Choose a reason for hiding this comment

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

빈으로 등록해서 쓰셨네요 굿

private BoardRepository boardRepository;

@BeforeEach
void setUp() {
Copy link
Member

Choose a reason for hiding this comment

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

BeforeEach로 매번 생성하기 보다는 BoardRepository를 빈으로 등록해놨으니 빈 주입을 받아서 쓰는게 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

그거 @bean 으로 했더니 객체를 한번만 만들더라구요.. Test Isolation 이 안되서 어쩔수 없이 매번 생성하였습니다. Isolation 하는 방법좀 알려주세요.

Copy link
Member

Choose a reason for hiding this comment

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

@mingimin 원래 의도하신게 Isolation이면 지금처럼 해도 좋을 것 같습니다 👍 제가 착각했네요 죄송합니다

Choose a reason for hiding this comment

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

Repository에서 데이터를 직접 들고 관리하다보니 이런 문제가 생겼군요. DB를 사용하게되면 트랜잭션 레벨로 분리가 되겠지만,
한번 자바스타일에 맞게끔 분리해보는 것도 좋을것 같네요!

private String title;
private String body;

public static class Builder {
Copy link
Member

Choose a reason for hiding this comment

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

Builder패턴....!!

}

@PostMapping("/board")
public ResponseEntity<BoardCreateResponse> create(@RequestBody HashMap<String, Object> map) {

Choose a reason for hiding this comment

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

(@RequestBody Board board)
이런식으로 받아올 수 있어요.
빌더 연습하려고 하신거면 죄송

private BoardRepository boardRepository;

@BeforeEach
void setUp() {

Choose a reason for hiding this comment

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

Repository에서 데이터를 직접 들고 관리하다보니 이런 문제가 생겼군요. DB를 사용하게되면 트랜잭션 레벨로 분리가 되겠지만,
한번 자바스타일에 맞게끔 분리해보는 것도 좋을것 같네요!

assertNotEquals(title, updatedBoard.getTitle());
assertEquals(newTitle, updatedBoard.getTitle());
assertNotEquals(body, updatedBoard.getBody());
assertEquals(newBody, updatedBoard.getBody());

Choose a reason for hiding this comment

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

TDD로 구현하신건가요??

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.

6 participants