snaag / TIL

https://github.com/snaag/todo3/issues
3 stars 0 forks source link

22-11-15-TUE #13

Open snaag opened 2 years ago

snaag commented 2 years ago
snaag commented 2 years ago

스프링 입문강의 > 회원 관리 예제 - 백엔드 개발

회원 리포지토리 테스트 케이스 작성

테스트 작성 규칙

테스트 작성 /w junit -> assertEquals

package hello.hellospring.repository;

import hello.hellospring.domain.Member;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import javax.swing.text.html.Option;
import java.util.List;
import java.util.Optional;

@Test
public void save() {
  Member member = new Member();
  member.setName("spring");

  repository.save(member);
  Member result = repository.findById(member.getId()).get();

  Assertions.assertEquals(result, member);
}

테스트 작성 /w assertj -> assertThat

package hello.hellospring.repository;

import hello.hellospring.domain.Member;
import org.assertj.core.api.Assertions;

import javax.swing.text.html.Option;
import java.util.List;
import java.util.Optional;

@Test
public void save() {
  Member member = new Member();
  member.setName("spring");

  repository.save(member);
  Member result = repository.findById(member.getId()).get();

  assertThat(member).isEqualTo(result);
}

매 테스트가 끝나면 실행되는 callback method = @AfterEach

@AfterEach
public void afterEach() {
  repository.clearStore();
}

Optional 의 값 꺼내기 -> .get()

Member result1 = repository.findByName("spring1").get();

TDD?