Questions tagged [mockk-verify]
28 questions
0
votes
2 answers
mockk, how to verify a function is called with Map type and interface type
The class has a function:
fun theFunc(uri: Uri, theMap: Map?, callback: ICallback) {
......
}
and would like to verify it is called with proper params type
io.mockk.verify { mock.theFunc(ofType(Uri::class), ofType(Map

lannyf
- 9,865
- 12
- 70
- 152
0
votes
0 answers
Mockk "verify" takes up to 6 seconds when verifying method with 3 or more parameters
I use mockk (versions 1.12.0 and 1.12.3) in @SpringBootTest in order to create a spy of some service and verify later that the service's method was (or was not) called. This looks like this:
@SpringBootTest
class MyTests {
@Autowired
private…

Kalich
- 87
- 2
- 6
0
votes
0 answers
java.lang.AssertionError: Verification failed: call 1 of 2: Router(mockRouter#172).xyz()) was not called
I am getting weird issue when running on my unit test. I have this function
internal fun getPendingStatusAction(
status: XYZ
): (() -> Unit)? {
var action: (() -> Unit)? = null
this.yo = yo
if (isAwaitingIdVerification(status)) {
…

Kotlin Learner
- 3,995
- 6
- 47
- 127
0
votes
1 answer
How to verify a top level function was called with Mockk?
How to verify that a top level (static) function was called in a test with MockK?
Simple approach like:
verify { someTopLevelFunction("some text") }
results in io.mockk.MockKException: can't find stub kotlin.Unit.

georgij
- 2,054
- 4
- 27
- 43
0
votes
1 answer
Get number of invocations
Does MockK provide a way of finding how many times a method has been invoked on a mock object?
I'm looking for something like Mockito.mockingDetails(mock).getInvocations(), but for MockK.
I can only find a way of checking how many invocations there…

k314159
- 5,051
- 10
- 32
0
votes
1 answer
mockk, get error when using mockkstatic for stub static function
using io.mockk 1.11.0
having some class with @JvmStatic function
class LogUtil {
@JvmStatic
fun logData(jsonStr: String) {
val jsonObj = getDataJson(jsonStr)
if (jsonObj == null) {
Log.e("+++", "+++ wrong json")
…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
Junit And Mockito, Capturing method call on passed argument
I am relatively new to Mockito and Junit in Java. How can I capture or verify the interaction on the argument passed to function that I am testing.
Ex-- Main class
public class A{
public void setValues(Person p){
p.setFirstName('Lucky');
…

Jay Yadav
- 236
- 1
- 2
- 10
0
votes
1 answer
Branches coverage in Mockk Kotlin
I am using mockk library in Kotlin. I am covering branch coverage. I am new to testing. Can someone tell me how to cover all branches? In the given below example, it has two objects one is id as string and the name which is hidden is list.…

Kotlin Learner
- 3,995
- 6
- 47
- 127
0
votes
1 answer
How to ignore testing of one of the attribute in an argument passed in function using verify method of Mockk
As I need to test publish function parameter passed is correct using Mockk in Kotlin
Below is the code :
val notificationData = NotificationData(
notificationId = "test-notificationID",
operation = "CREATE",
…

Mayur Jain
- 155
- 1
- 8
0
votes
0 answers
MockK - Are multiple calls to verify() with different "exact =" in the same test supported?
I have strange behaviour. I have a unit-test that does some stuff and then performs the following verification statements:
verify(exactly = 2) {
observer.onThingChanged()
}
verify(exactly = 1) {
b.addThing(thing)
}
…

David Wasser
- 93,459
- 16
- 209
- 274
0
votes
1 answer
mockk, how to verify a specific exception is thrown
using mockk 1.9.3, junit 4
having a function which will report the exceptions for different conditions, need to test and verify the correct exception is reported.
class NetworkApi {
fun actionAndLogExceptions(appContext: Context, optionalParams:…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
mockk, how to use slot for MutableMap
using mockk 1.9.3
having a function to be verified
class EventLogger private constructor()
fun logUserEvent(eventName: String?, eventParamMap: MutableMap?) {
......
internaLogEventImpl(eventName, eventParamMap)
}
internal fun…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
Verify constructor lambda using mockk
I want to verify the number of calls being invoked by the lambda.
This lambda serves as a callback to deliver the state changes. I want to constraint the lambda to be used only via constructor.
Is there any way to test this when lambda is in…

user3354265
- 777
- 1
- 10
- 26