-
리포지터리 데이터 삭제하기 부분 개수 오류JAVA/스프링 2023. 8. 23. 13:16
@Test @Transactional @DirtiesContext void 데이터_삭제하기() { assertEquals(3,this.quastionRepository.count()); Optional<Quastion> optionalQuastion = this.questionRepository.findById(2L); // Optional은 null을 허용하는 클래스 // this.questionRepository 해당 리포지터리에서 ID값이 2인 Quastion을 조회. 2L은 Long타입의 아이디 값 조회 assertTrue(optionalQuestion.isPresident(), “Question with ID 1 should exist”); Question question = optionalQuestion.get(); this.questionReporsitory.delete(question); assertEquals(2, this.questionRepository.count()); }
계속 테스트에 실패하고 개수 오류가 났었는데
데이터베이스를 잘 ! 확인 하도록 하자
디비에서 확인 했을 때 아이디값이 2부터 시작하므로 findById값에 2L을 넣어주고
3개의 데이터에서 1개를 뺐으므로 2가 나와야함
특히 Int 타입인지 Long 타입인지 잘 확인하기.'JAVA > 스프링' 카테고리의 다른 글
question_from.html 코드 분석 (0) 2023.08.25 템플릿엔진 오류 (0) 2023.08.24 엔티티 복습 (2) 2023.08.20 Controller 복습 (0) 2023.08.20 Get과 Post의 차이 (0) 2023.08.15