반응형
테스트 케이스를 만들고 테스트를 해보겠습니다. 아래와 같이 테스트 패키지-hello.hellospring 패키지 아래에 repository패키지와 MemoryMemberRepositoryTest클래스를 구성합니다.
1. MemoryMemberRepositoryTest클래스
package hello.hellospring.repository;
import hello.hellospring.domain.Member;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class MemoryMemberRepositoryTest {
MemoryMemberRepository repository = new MemoryMemberRepository();
@AfterEach
public void afterEach(){
repository.clearStore();
}
@Test
public void save(){
Member member = new Member();
member.setName("spring");
repository.save(member);
Member result = repository.findById(member.getId()).get();
//Assertions.assertEquals(member, null); (기대값, 실제값)
assertThat(member).isEqualTo(result); //(기대값, 실제값)
}
@Test
public void indByName(){
Member member1 = new Member();
member1.setName("spring1");
repository.save(member1);
Member member2 = new Member();
member2.setName("spring2");
repository.save(member2);
Member result = repository.findByName("spring1").get();
assertThat(result).isEqualTo(member1);
}
@Test
public void findAll(){
Member member1 = new Member();
member1.setName("spring1");
repository.save(member1);
Member member2 = new Member();
member2.setName("spring2");
repository.save(member2);
List<Member> result = repository.findAll();
assertThat(result.size()).isEqualTo(2);
}
}
반응형
'Programming > Spring' 카테고리의 다른 글
Spring boot 시작하기 - 5강(테스트) (0) | 2020.11.26 |
---|---|
Spring boot 시작하기 - 5강(Service) (0) | 2020.11.26 |
Spring boot 시작하기 - 4강(회원 도메인과 리포지토리) (0) | 2020.11.25 |
Spring boot 시작하기 - 3강(파라미터 있는 MVC) (0) | 2020.11.23 |
Spring boot 시작하기 - 2강(MVC예) (0) | 2020.11.23 |