Questions tagged [mockk-verify]

28 questions
21
votes
1 answer

How to check if a method was not invoked with mockk?

I need to check if a method was not invoked in my unit tests. This is an example test I did that checks if the method was invoked and it works perfectly fine: @Test fun viewModel_selectDifferentFilter_dispatchRefreshAction() { val selectedFilter…
Pierre Vieira
  • 2,252
  • 4
  • 21
  • 41
3
votes
1 answer

mockito, in koltin how to verify a static method

Having a kotlin singleton static method internal object TestSingleton { @JvmStatic fun staticMethod1 (str: String) { println("+++ === +++ TestSingleton.staticMethod(), $str") staticMethod2 (str) } @JvmStatic fun…
lannyf
  • 9,865
  • 12
  • 70
  • 152
2
votes
2 answers

Mockk matching and overloaded function withArg

Hello I am trying to find a way to match an overloaded function inside of the verify using withArg The doc doesnt really point this out every { getResponse.Ids } returns listOf(121212L) assert( client.getExtIds(Ids) ) verify { …
Bao Thai
  • 533
  • 1
  • 6
  • 25
1
vote
0 answers

Why is Mockk failing and calling real method when doing coVerify(exactly = 0)

I have recently started programming in Kotlin and for writing unit test I am using Mockk library. I am stuck at a particular point where Mockk fails while mocking a generic class. I have a class called KafkaService which looks like this and this is…
ashwini abhishek
  • 206
  • 5
  • 12
1
vote
0 answers

Why is mockk executing a method when I'm checking for not invoked scenario?

I have a scenario like fun someMethod() { try { val response = callApi.method() val output = processResponse(response) } catch (throwable: Throwable) { } } Now I'm testing for the scenario when callApi.method() throws an…
AndroidDev
  • 5,193
  • 5
  • 37
  • 68
1
vote
1 answer

What is the analogue of Mockito.verifyZeroInteractions(obj) in the Mockk library?

I want to switch to Mockk, but i cant find analogue of this method in Mockk It doesn't work verify (exactly = 0) { obj }
KramRus
  • 13
  • 3
1
vote
0 answers

How can I mock callback pass in constructor

I have below class that has callback.How Can I mockk ResponseReceiver(callback) class Receiver(private val context: Context) { val responses: Flow = callbackFlow { val callback = object : Server { override fun…
Pause
  • 33
  • 9
1
vote
1 answer

Mockk verify is trying to verify Log.d() which is never been called

So, I have written unit test as follows. Which basically calls a method in Viewmodel class. @Test fun `on clear Cached Calls AppUtility ClearCache`() { sut.clearCache() verify(exactly = 1) { …
AkshayT
  • 2,901
  • 2
  • 28
  • 32
1
vote
2 answers

How to test async function in Mockk Kotlin

I want to test this function. suspend fun fetchTwoDocs() = coroutineScope { val deferredOne = async { fetchDoc(1) } val deferredTwo = async { fetchDoc(2) } deferredOne.await() …
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
1
vote
0 answers

mocking a private function with suspend higher order function as argument with Mockk

Actually issue is, i am unable to mock a private function due to suspendable lambda as arguement (val condition: suspend () -> AppResult) So, in that regard i need your assistance. Code to be tested, class UserPlayListManagerImpl( private…
Reprator
  • 2,859
  • 2
  • 32
  • 55
1
vote
1 answer

Verify exact number of invocations within verifyOrder

I want to verify that a number of functions were called in a specific order, but one of the functions gets called N times: verifyOrder { myMockObject.func1() (exactly = 10) myMockObject.func2() myMockObject.func3() } How do I specify…
k314159
  • 5,051
  • 10
  • 32
1
vote
0 answers

How to use mockk in view binding

Hi i am new in Mockk library Kotlin. I want to mock view binding in unit testing. But i am unable to get proper example. I search Possible to mock/test Android ViewBinding interactions? I don't want to use @RunWith(PowerMockRunner::class). Does any…
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
0
votes
1 answer

Argument passed to verify() is of type KafkaProducerService and is not a mock

I get an error when running the below test. @ExtendWith(MockKExtension::class) class SenderServiceTest { @MockK lateinit var kafkaService: KafkaService @Test fun `Send message`() { val key = KeyType() …
ever alian
  • 1,028
  • 3
  • 15
  • 45
0
votes
1 answer

How to test subscribe call of Observable using Mockk?

I have a function in my ViewModel in which I subscribe to some updates, I want to write a test that will check that after the subscribe is triggered, the specific function is called from the subscribe. Here is how the function looks: fun…
John
  • 355
  • 2
  • 4
  • 15
0
votes
1 answer

Could not resolve 'spring-boot-security-test' when testing service with mockk

I'm currently getting the following error when I try to test my service: Execution failed for task ':compileTestKotlin'. > Error while evaluating property 'filteredArgumentsMap' of task ':compileTestKotlin'. > Could not resolve all files for…
JamieRhys
  • 206
  • 6
  • 24
1
2