@SpringBootTest
public class test {
@Autowired
private QuestionRepositories questionRepositories;
@BeforeEach
void setUp() {
Question q = new Question();
q.setSubject("제목1");
q.setContent("내용1");
q.setCreateDate(LocalDateTime.now());
questionRepositories.save(q);
}
@Test
@DisplayName("게시글수 확인")
void test2(){
List<Question> q1all = this.questionRepositories.findAll();
assertEquals(1, q1all.size());
Question q = q1all.get(0);
assertEquals("제목1",q.getSubject());
}
@Test
@DisplayName("아이디값을 조회")
void test3(){
Optional<Question> oq = this.questionRepositories.findById(1L);
if(oq.isPresent()) {
Question q = oq.get();
assertEquals("제목1",q.getSubject());
}
}
@Test
void testJpa() {
Question q = this.questionRepositories.findBySubject("제목1");
assertEquals(1L, q.getId());
}
}
public class test {
@Autowired
private QuestionRepositories questionRepositories;
@BeforeEach
void setUp() {
Question q = new Question();
q.setSubject("제목1");
q.setContent("내용1");
q.setCreateDate(LocalDateTime.now());
questionRepositories.save(q);
}
@Test
@DisplayName("게시글수 확인")
void test2(){
List<Question> q1all = this.questionRepositories.findAll();
assertEquals(1, q1all.size());
Question q = q1all.get(0);
assertEquals("제목1",q.getSubject());
}
@Test
@DisplayName("아이디값을 조회")
void test3(){
Optional<Question> oq = this.questionRepositories.findById(1L);
if(oq.isPresent()) {
Question q = oq.get();
assertEquals("제목1",q.getSubject());
}
}
@Test
void testJpa() {
Question q = this.questionRepositories.findBySubject("제목1");
assertEquals(1L, q.getId());
}
}
테스트 할때 값이 50씩 증가해
@BeforeEach
로 처음에 실행될때 스퀸스 값이 1씩 증가고 50개씩 미리 만들어두는건데 그거 영향받아서 그런거 같은데
맞아? 이걸 방지 하려면 어떻게 해야할까... 아무리 고민해봐도 모르겠음
말하는거랑 코드랑 다른데 어떻게 답을 내주냐 이건 AI도 답 못 내준다
클래스에 @Transactional 걸어둬라. @BeforeEach를 @BeforeAll로 바꿔라. 각 테스트 코드를 보면 setUp을 한 번만 실행시켜도 충분히 테스트 될 것 같은데? 그리고 @Test는 왜 인덴트가 안 맞냐 너는 입사해서 질문 이렇게 하면 사수한테 개뚜까맞고 쫓겨난다 엉망진창이네 그냥