Mockito framework site
Intro Why How More Who Links Training Why drink it? Mockito is a mocking framework that tastes really good. It lets you write beautiful tests with a clean & simple API. Mockito doesn’t give you hangover because the tests are very readable and they produc
site.mockito.org
Mockito - mockito-core 4.5.1 javadoc
Latest version of org.mockito:mockito-core https://javadoc.io/doc/org.mockito/mockito-core Current version 4.5.1 https://javadoc.io/doc/org.mockito/mockito-core/4.5.1 package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.m
javadoc.io
https://howtodoinjava.com/mockito/mockito-mock-injectmocks/
Mockito - Difference between @Mock and @InjectMocks annotations
Learn the difference between @Mock and @InitMocks annotations in mockito. Use @Mock and @InitMocks annotations to create objects and inject dependencies.
howtodoinjava.com
1. Mock 객체 생성하기
방법1. @Mock 어노테이션과 MockitoAnnotations를 이용한 초기화
방법2. inline 함수를 이용한 초기화
테스트마다 Mock 객체의 참조가 필요하므로 테스트 클래스의 멤버 변수로 Mock 객체를 들고 있는 게 유리하고,
따라서 어노테이션을 사용한 초기화를 하는 게 권장되는 방식입니다 😄
2. 어노테이션
//@Config targetSdk가 29 이상일 경우는 Robolectric에서 에러나는것을 방지
@Config(sdk = [Build.VERSION_CODES.O_MR1])
//coroutine 관련 api사용시 필요
@ExperimentalCoroutinesApi
// Android JUnit4를 사용하겠다.
@RunWith(AndroidJUnit4::class)
// Mockito 를 사용하겠다.
@RunWith(MockitoJUnitRunner::class)
// Rule은 테스트 클래스에서 동작 방식을 재정의 하거나 쉽게 추가하는 것을 가능하게 합니다.
// 사용자는 기존의 Rule을 재사용하거나 확장하는 것이 가능합니다.
@Rule
https://www.baeldung.com/junit-4-rules
Guide to JUnit 4 Rules | Baeldung
Learn how to use the JUnit 4 Rules Model to extend the behavior of JUnit tests
www.baeldung.com
https://nesoy.github.io/articles/2018-12/Junit-Rule
JUnit의 Rule이란?
nesoy.github.io
'Android 공부 > 단위테스트 관련' 카테고리의 다른 글
AndroidX 테스트용 ViewModel, Live Data 테스트 (0) | 2022.05.10 |
---|---|
단위테스트? : ( Mock ) 02 , 테스트 적용과정. (0) | 2022.05.09 |
Mocking 및 Unit test 작성 01 (0) | 2022.05.09 |
Mockito 설치 (0) | 2022.05.09 |
단위테스트? : (JUnit, Mock ) 01 (0) | 2022.03.21 |