Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi authored May 9, 2024
1 parent d26a48b commit b1a44aa
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions spring-code-for-deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,53 @@ public class PostJpaRepositoryTest {
}
```

### Repository를 Mocking 하고 Test 하는 경우

Mocking은 실제 객체가 아닌 가짜 객체를 생성하여 Test를 작성하는 것 또는 그러한 기술을 의미함.


MemberRetrieverTest
- Member를 조회해오는 test에서 MemberJpaRepository를 Mocking하여 Test를 작성

```Java
@SpringBootTest
@ActiveProfiles("test")
public class MemberRetrieverTest {

@Autowired
MemberRetriever memberRetriever;

@MockBean
MemberJpaRepository memberJpaRepository;

@Test
void test() throws Exception {
// given
BDDMockito.when(
memberJpaRepository.findById(1L)
).thenReturn(
Optional.ofNullable(Member.builder()
.age(99)
.name("오해영")
.nickname("5hae0")
.build())
);
// when
Member findMember = memberRetriever.findById(1L);

// then
assertThat(findMember)
.extracting("age", "name", "nickname")
.containsExactly(99, "오해영", "5hae0");
}
}
```



## Service Test

## Controller Test

### 통합 테스트
Test Coverage 확보를 위해서 통합 테스트 또한 작성할 수 있습니다.

0 comments on commit b1a44aa

Please sign in to comment.