Skip to content

Instantly share code, notes, and snippets.

@theapache64
Created April 25, 2020 05:26
Show Gist options
  • Save theapache64/d92703067b1d99239d1bb15072959ceb to your computer and use it in GitHub Desktop.
Save theapache64/d92703067b1d99239d1bb15072959ceb to your computer and use it in GitHub Desktop.
package com.theapache64.mockitosample
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
class Calculator {
fun add(x: Int, y: Int) = x + y
}
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@Mock
lateinit var calculator: Calculator
@Before
fun before() {
MockitoAnnotations.initMocks(this)
}
@Test
fun test() {
assertEquals(calculator.add(10, 10), 20)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment