Mockito는 자바에서 단위테스트를 하기 위해 Mock을 만들어주는 프레임워크
https://static.javadoc.io/org.mockito/mockito-core/2.22.0/org/mockito/Mockito.html
Mockito (Mockito 2.22.0 API)
Use doCallRealMethod() when you want to call the real implementation of a method. As usual you are going to read the partial mock warning: Object oriented programming is more less tackling complexity by dividing the complexity into separate, specific, SRPy
static.javadoc.io
Dependency
// using
dependencies {
testImplementation "org.mockito:mockito-core:+"
androidTestImplementation "org.mockito:mockito-android:+"
testImplementation "org.mockito:mockito-inline:+" // MockMaker 설정없이 사용하기 위해
}
Sample
//using mock
mockedList.add("once");
mockedList.add("twice");
mockedList.add("twice");
mockedList.add("three times");
mockedList.add("three times");
mockedList.add("three times");
//following two verifications work exactly the same - times(1) is used by default
verify(mockedList).add("once");
verify(mockedList, times(1)).add("once");
//exact number of invocations verification
verify(mockedList, times(2)).add("twice");
verify(mockedList, times(3)).add("three times");
//verification using never(). never() is an alias to times(0)
verify(mockedList, never()).add("never happened");
//verification using atLeast()/atMost()
verify(mockedList, atMostOnce()).add("once");
verify(mockedList, atLeastOnce()).add("three times");
verify(mockedList, atLeast(2)).add("three times");
verify(mockedList, atMost(5)).add("three times");
'모바일 프로그래밍 > 안드로이드' 카테고리의 다른 글
FloatingActionButton Behavior (0) | 2019.06.14 |
---|---|
RecyclerView Dummy Adapter (0) | 2019.06.10 |
Android FCM (0) | 2019.04.22 |
시스템 앱으로 설치하는 방법 (How to Install Android System App) (1) | 2019.04.17 |
드로이드 나이츠 영상 (0) | 2019.04.17 |
댓글