Questions tagged [mockito-kotlin]

a library for Kotlin that provides helper functions to work with Mockito, a popular mock framework.

A library that provides helper functions to work with Mockito in Kotlin. Mockito is a popular mock framework.

66 questions
1
vote
0 answers

ExceptionInInitializerError when mocking Kotlin suspend function using mockito-kotlin

I'm writing a Kotlin unit test in Android (/test) and I am getting an error when mocking a suspend function I'm using testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" And have some code: @Test fun MyTest() = runBlocking { …
tenprint
  • 1,123
  • 1
  • 11
  • 29
1
vote
0 answers

PowerMockito.verifyStatic throws NotAMockException

/** * Testing Shared preferences with mocking the static methods in Prefs. * This helps us where a test suite is failing, in long run */ @Test fun testSharedPrefs_returnsMockedPrefs(){ //Mocking all the static methods in Prefs.java …
1
vote
0 answers

Mockito-Kotlin exception: UnfinishedStubbingException

I am writing a BDD test with Cucumber and mockito_kotlin. The verify function is like: @Then("there shouldn't be any coockie eaten.") fun there_shouldnt_be_any_coockie_eaten() { verify(mockCoockie, never()).eatGoodCookie()(any(),…
1
vote
0 answers

Type inference of spied higher-order functions

I'm developing a unit test on Android, using mockito-kotlin. I was trying to spy on a function so I did the following code to do that, and it works fine. In this case AndroidStudio pointed out that the cast was unnecessary, but when the cast is…
Luciano Ferruzzi
  • 1,042
  • 9
  • 20
1
vote
0 answers

Mockito, what does @Mock really do to object

As I understood, Mockito @Mock created a stub with empty methods or methods that otherwise return a default object for each type. On contrary to @Spy which wraps the instance so that you use the actual implementation but still be able to mock…
htafoya
  • 18,261
  • 11
  • 80
  • 104
1
vote
1 answer

Unit test fails when mocked object is inside lambda, but works when it's outside lambda and used inside lambda?

I have a dialog that I'm doing some unit tests on using Mockito / Mockito Kotlin. When the user clicks on the dialog, the user is shown a list of times, and then their selection assigns the value and then does some other work with it. I have a…
Ben987654
  • 3,280
  • 4
  • 27
  • 50
1
vote
1 answer

How to create ArgumentMatchers.any(type: Class) for testing in Kotlin?

I'm trying to unit test a class that uses the following service: parserService.parseJsonStringToModel(json: String, adapterClass: Class): T? My first approach was to use ArgumentMatchers to implement unit testing as…
AlexTa
  • 5,133
  • 3
  • 29
  • 46
0
votes
1 answer

Kotlin Mockito calls mocked method

I've been away from mockito for awhile, so this is probably a newbie issue. package somepackage import org.junit.jupiter.api.Test import org.mockito.kotlin.doNothing import org.mockito.kotlin.mock import org.mockito.kotlin.whenever var called =…
Kurt
  • 399
  • 3
  • 14
0
votes
0 answers

Using mockk, 2 files found with path 'dispatcher.jar'

I am trying to setup a mockk mock for a test: @RunWith(AndroidJUnit4::class) class MyTest { @Test fun canary() { } } I ran into: 6 files found with path 'META-INF/LICENSE.md'. 6 files found with path 'META-INF/LICENSE-notice.md'. I added…
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
0
votes
1 answer

Android: Mocking GoogleSignIn.getClient is resulting in Null Pointer Exception

Trying to mock static object GoogleSignIn.getClient() method but getting this error from the initialize() method: getClient(context, gso) must not be null java.lang.NullPointerException: getClient(context, gso) must not be null Here is the class…
rysv
  • 2,416
  • 7
  • 30
  • 48
0
votes
1 answer

How to verify in unit test that a method being tested is calling its super method (method in parent class)

Class A: Class being tested. Class A extends class B and overrides its method common(). i.e. class B { fun common() {} } class A : B { override fun common() { if(x) { doSomething() } else super.common() } } Now if you are…
Bharat
  • 904
  • 6
  • 19
0
votes
0 answers

Kotlin - android - MockitoAnnotations.openMocks() throws an exception related to matchers

I have the following setup: @Mock lateinit var dialogEventObserver: Observer @Mock lateinit var detailsObserver: Observer private fun setup() { MockitoAnnotations.openMocks(this) viewModel =…
nightfixed
  • 871
  • 1
  • 12
  • 24
0
votes
1 answer

Method isDigitsOnly in android.text.TextUtils not mocked Error

I created a validation use case in which I'm validating the input using isDigitsOnly that use TextUtils internally. override fun isDigitsOnly(size: String): Boolean { return !size.trim().isDigitsOnly() } when I tried to test it, I got this…
Omar Redani
  • 131
  • 5
0
votes
1 answer

How can we mock a private data member of a class in kotlin using Mockito?

Let suppose, we have a class Employee having some private data members and public methods in it. I want to create a Junit test case to cover whether the method is called or not. class Employee constructor(employeeName: String?){ private var…
0
votes
0 answers

How to use mockito to test retrofit2 response?

With mockito, I want to test a retrofit response. Can you guide me in this.. I am new in unit testing with mockito so if you can guide me try to explain your answer a little bit. viewModel fun loginUser() { repository.loginUser(this,…