Created
April 25, 2020 05:26
-
-
Save theapache64/d92703067b1d99239d1bb15072959ceb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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