Skip to content

Instantly share code, notes, and snippets.

@ProArun
Created August 19, 2023 17:38
Show Gist options
  • Save ProArun/00ebf801b8fce1af8e8bb40cf1b5e581 to your computer and use it in GitHub Desktop.
Save ProArun/00ebf801b8fce1af8e8bb40cf1b5e581 to your computer and use it in GitHub Desktop.
convert instrumentation test to jvm test
class QuoteManagerTest{
@Mock
lateinit var context: Context
@Mock
lateinit var assertManager: AssertManager
@Before
fun setup(){
MockitoAnnotations.openMocks(testClass:this)
}
@Test
fun test(){
val testStream = QuoteManagerTest::class.java.getResourceAsStream("/quotes.json")//add quotes.json in test/resources folder
doReturn(assertManager).`when`(context).asserts
Mockito.`when`(context.asserts.open(anyString())).thenReturn(testStream)
val sut = QuoteManager()
sut.populateQuoteFromAssets(context,"fileName: "")
val quote = sut.getCurrentQuote()
Assert.assertEquals("Well begun is half done",quote.text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment