smassive
11/28/2018, 11:00 AMsmassive
11/28/2018, 11:03 AM@Before
fun setUp() {
declareMock<ComponentA>()
val componentA = get<ComponentA>()
BDDMockito.`when`(componentA.foo()).thenReturn(bar)
}
smassive
11/28/2018, 11:03 AMJohannes Waltsgott
11/28/2018, 11:14 AM@LargeTest
@RunWith(AndroidJUnit4::class)
class MockedTest : KoinTest {
// will be mocked
val contactFormRepo: ContactFormRepository by inject()
@Rule
@JvmField
// As interaction with mock starts in activity's
// onCreate we can't launch it before mock configuration
val rule = object :
ActivityTestRule<ContactFormActivity>(ContactFormActivity::class.java, false, false) {}
@Before
fun setUp() {
declareMock<ContactFormRepository>()
}
@After
fun tearDown() {
rule.finishActivity()
}
@Test
fun shouldShowError() {
whenever(contactFormRepo.submitForm(...)) .thenReturn(Completable.error(Throwable()))
rule.launchActivity(null)
// test goes here
}
}
}
smassive
11/28/2018, 11:46 AM