New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken spying on functions #1033
Comments
I can confirm this worked on the previous version 1.13.3. val lambda = spyk<() -> Unit>()
// or
val lambda: () -> Unit = spyk() |
For non-trivial spy'd lambdas such as ones that need to return a value, the following seems to be necessary:
EDIT: Or moving the |
Thanks for this answer, helped me find a solution for my very similar problem. I had to change me spyk instantiation from this:
to this:
what I still get which is new since the update is this slf4j logger provider warning:
|
SLF4J version 2.0.5 is a dependency of mockk. This specific issue happens when your slf4j version is updated, but your logback version is old.
|
I have the same problem when spying on Fails: spyk(
MyFunInterface { 1 + 2 }
) Works: spyk(
object : MyFunInterface {
override fun doThing(): Int = 1 + 2
}
) |
I'm experiencing the same problem in 1.13.4. I downgraded to 1.13.3, and it is being used temporarily. ex) interface Logger {
fun interface Factory {
fun getLogger(name: String): Logger
fun getLogger(clazz: Class<*>): Logger = getLogger(clazz.name)
}
}
// Error Occurred
val sut = spyk(Logger.Factory { NoOpLogger })
sut.getLogger(LoggerTest::class.java)
verify(exactly = 1) {
sut.getLogger(any<String>())
} |
Improve performance of `Tracer.invoke()`: - ~70% improvement if there are no trace event consumers - ~55% improvement if there are trace event consumers Changes: * Introduce caching of trace event method annotations in the `Tracer.invoke()` function. * Skip creation of a `TraceEvent` object if there are no event consumers. This saves us from performing an expensive `LocalDateTime.now()` call. * Skip retrieval of trace event method annotations for simple log function invocations, if there are no event consumers. * Remove string concatenations in `createLogMessage()` functions. Only use `StringBuilder` functions. * Change `toStringRegistry` to use `item::javaClass.name` as key, and use `item::class.toString()` only as fallback. * Skip reading `item.javaClass.getMethod("toString").declaringClass` in `convertToStringUsingRegistry()`: the `item.toString()` function of `Any` will anyway print the name of the class. * Fix execution of unit tests requiring mockk-jvm (`extensions` and `traceevents` modules): no unit test for these modules was being run anymore, after the 1.8.2 update. * Fix the `IfExtensionsTest` unit tests: these tests were broken by mockk 1.13.4 (due to mockk/mockk#1033).
* Improve performance of Tracer.invoke() function Improve performance of `Tracer.invoke()`: - ~70% improvement if there are no trace event consumers - ~55% improvement if there are trace event consumers Changes: * Introduce caching of trace event method annotations in the `Tracer.invoke()` function. * Skip creation of a `TraceEvent` object if there are no event consumers. This saves us from performing an expensive `LocalDateTime.now()` call. * Skip retrieval of trace event method annotations for simple log function invocations, if there are no event consumers. * Remove string concatenations in `createLogMessage()` functions. Only use `StringBuilder` functions. * Change `toStringRegistry` to use `item::javaClass.name` as key, and use `item::class.toString()` only as fallback. * Skip reading `item.javaClass.getMethod("toString").declaringClass` in `convertToStringUsingRegistry()`: the `item.toString()` function of `Any` will anyway print the name of the class. * Fix execution of unit tests requiring mockk-jvm (`extensions` and `traceevents` modules): no unit test for these modules was being run anymore, after the 1.8.2 update. * Fix the `IfExtensionsTest` unit tests: these tests were broken by mockk 1.13.4 (due to mockk/mockk#1033). * Address review comments
This is still a problem in 1.13.7. |
Expected Behavior
Calling a line like
val test: (Int) -> Unit = spyk({})
shouldn't fail.Current Behavior
Running this line fails with:
Failure Information (for bugs)
This got likely broken because of the
ProxyMaker
deduplication of #1024Steps to Reproduce
val test: (Int) -> Unit = spyk({})
to a unit testContext
The text was updated successfully, but these errors were encountered: