Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210606] Mockito #140

Open
JuHyun419 opened this issue Jun 6, 2021 · 0 comments
Open

[20210606] Mockito #140

JuHyun419 opened this issue Jun 6, 2021 · 0 comments

Comments

@JuHyun419
Copy link
Owner

JuHyun419 commented Jun 6, 2021

Mockito

테스트 할 때 Spring에 의존성이 필요하다면 @MockBean을 사용하면 되고, 의존성 없는 로직을 테스트할 경우에는 @Mock을 사용하면 됩니다.
  • 스텁(stubbing)
스텁(stubbing)은 어떤 로직을 가지고 있는 것이 아닌, 미리 지정한 값을 반환하는 것을 뜻함
when().then() 형식으로 사용
when() -> 호출할 조건
then() -> 반환할 값

@Mock
List mockedList; 

// stubbing
when(mockedList.get(0)).thenReturn("Hello");
when(mockedList.get(1)).thenThrow(new RuntimeException()); 
System.out.println(mockedList.get(0)); // "Hello" 출력
System.out.println(mockedList.get(1)); // runtime exception이 발생
System.out.println(mockedList.get(10)); // 10번째는 스텁을 하지 않았기 때문에 null이 출력됨

알고리즘 - Stack, 아스키코드

  • 괄호 삽입삭제, 문자열 삽입삭제 등의 문제 -> Stack 고려해볼 것
  • 알파벳 <-> 숫자 변환할 때 -> 아스키코드 고려해볼 것

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant