WrongTypeOfReturnValue

nero·2023년 8월 4일
0

발생한 오류

org.mockito.exceptions.misusing.WrongTypeOfReturnValue: 
StatsModel cannot be returned by toString()
toString() should return String
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests.
   Please refer to Mockito FAQ on limitations of concurrency testing.
2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - 
   - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.

오류가 난 코드

//Before
 doReturn(new CategoryNotFountException())
                .when(categoryService)
                .getDetail(-1L);
                
//after
 doThrow(new CategoryNotFountException())
                .when(categoryService)
                .getDetail(-1L);

결론

예외값은 doThrow를 사용합시다!

profile
겸손하게 배우는 개발자입니다

1개의 댓글

comment-user-thumbnail
2023년 8월 4일

유익한 글이었습니다.

답글 달기