07-20-2023, 03:08 PM
I want to implement some UI Tests to assure that the code implemented today works for tomorrow but when trying to see if already UI tests implemented in the past works, it throws this error:
`Caused by: io.mockk.MockKException: Failed matching mocking signature for left matchers: [any(), any()]`
This happens on an `every {} return Unit` line which there's a **object file called WakeUpTimeManager**, that **calls a .set(param1, param2)** function and **inside that function there are some inline functions** which I think it could be causing the problem but I don't know. I tried searching on the internet but couldn't find a solution.
Here's the test that throws the error:
```
@Before
fun setup() {
mockkObject(WakeUpTimerManager)
every { WakeUpTimerManager.set(any(), any()) } returns Unit
}
```
Here's the function that is calling on `every` line
```
fun set(context: Context, timer: Timer) {
if (timer.atMillis < System.currentTimeMillis()) {
return
}
if (Preset.findByID(context, timer.presetID) == null) {
return
}
//This is an inline function
withGson {
PreferenceManager.getDefaultSharedPreferences(context).edit {
putString(PREF_WAKE_UP_TIMER, it.toJson(timer))
}
}
//This is an inline function
withAlarmManager(context) {
it.setAlarmClock(
AlarmManager.AlarmClockInfo(timer.atMillis, getPendingIntentForActivity(context)),
getPendingIntentForService(context, timer)
)
}
}
```
**Question:** Why does mockk throw this error? What's going on? Is there any solution for this?
`Caused by: io.mockk.MockKException: Failed matching mocking signature for left matchers: [any(), any()]`
This happens on an `every {} return Unit` line which there's a **object file called WakeUpTimeManager**, that **calls a .set(param1, param2)** function and **inside that function there are some inline functions** which I think it could be causing the problem but I don't know. I tried searching on the internet but couldn't find a solution.
Here's the test that throws the error:
```
@Before
fun setup() {
mockkObject(WakeUpTimerManager)
every { WakeUpTimerManager.set(any(), any()) } returns Unit
}
```
Here's the function that is calling on `every` line
```
fun set(context: Context, timer: Timer) {
if (timer.atMillis < System.currentTimeMillis()) {
return
}
if (Preset.findByID(context, timer.presetID) == null) {
return
}
//This is an inline function
withGson {
PreferenceManager.getDefaultSharedPreferences(context).edit {
putString(PREF_WAKE_UP_TIMER, it.toJson(timer))
}
}
//This is an inline function
withAlarmManager(context) {
it.setAlarmClock(
AlarmManager.AlarmClockInfo(timer.atMillis, getPendingIntentForActivity(context)),
getPendingIntentForService(context, timer)
)
}
}
```
**Question:** Why does mockk throw this error? What's going on? Is there any solution for this?