[Junit] 2024-06-23 오류 기록

김탁형·2024년 6월 25일
  1. 프로젝트 : hhpls-tdd-jvm
  2. 파일 : serviceImplTest.java
  3. 내용
org.mockito.exceptions.misusing.MissingMethodInvocationException: 
when() requires an argument which has to be 'a method call on a mock'.
For example:
    when(mock.getArticles()).thenReturn(articles);

Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
   Those methods *cannot* be stubbed/verified.
   Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.
  1. 의심 : method 가 Mock 으로 가상Repository을 선언해야하는데 실제 Repository를 호출함.
  2. 수정
    @Autowired
    private UserPointRepositoryImpl userPointRepositoryImpl;
    @Autowired
	private PointServiceImpl pointServiceImpl;

-> 수정

    @Mock
    UserPointRepository userPointRepository;
    @Mock
    PointService pointService;
  1. 결론 : method 호출 완료 단위테스트가 목적
profile
김탁형/성남/31

0개의 댓글