Message from Assertk assertions is not printed when using withArg block.
See original GitHub issuePrerequisites
Please answer the following questions for yourself before submitting an issue.
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
Expected Behavior
The message from AssertionFailedError (which is thrown by Assertk lib) should be printed when assertion is performed in withArg block.
Current Behavior
The message from AssertionFailedError (which is thrown by Assertk lib) exception is not printed when the checking is performed in withArg block.
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- MockK version: 1.11.0
- OS: macOS Big Sur
- Kotlin version: 1.5
- JDK version: 11
- JUnit version: 5
- Type of test: unit test
Minimal reproducible code (the gist of this issue)
// -----------------------[ GRADLE DEFINITIONS ] -----------------------
project.ext.versions = [
junit : '5.7.2',
assertk : '0.24',
mockk : '1.11.0'
]
dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: versions.junit
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: versions.junit
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: versions.junit
testImplementation group: 'com.willowtreeapps.assertk', name: 'assertk-jvm', version: versions.assertk
testImplementation group: 'io.mockk', name: 'mockk', version: versions.mockk
}
// -----------------------[ YOUR CODE STARTS HERE ] -----------------------
package some.example.com
import io.mockk.every
import io.mockk.mockk
import org.apache.kafka.common.KafkaFuture
import kotlin.test.Test
class SomeExampleTest {
val orderRepository: OrderRepository = mockk()
val orderService: OrderService = OrderService(orderRepository)
@Test
fun test() {
// given
thereIsOrder(anOrder())
// when
orderService.pay(anOrderPayment())
// then
wasSaved(anOrder())
}
fun wasSaved(order: Order, times: Int = 1) {
verify(exactly = times) {
orderRepository.save(withArg{ equalsTo(order) })
}
}
private fun MockKAssertScope.equalsTo(order: Order) {
assertThat(this.actual as Order)
.hasCommandId(order.commandId)
.hasOrderId(order.orderId)
// and so on
}
// walk around
private fun MockKAssertScope.equalsToAndLog(order: Order) {
try {
assertThat(this.actual as Order)
.hasCommandId(order.commandId)
.hasOrderId(order.orderId)
// and so on
} catch (t: Throwable) {
logger.error(t) {}
throw t
}
}
}
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
I found that exception is catched here, and the stacktrace is not logged.
package io.mockk
data class FunctionMatcher<in T : Any>(
val matchingFunc: (T) -> Boolean,
override val argumentType: KClass<*>
) : Matcher<T>, TypedMatcher, EquivalentMatcher {
override fun equivalent(): Matcher<Any> = ConstantMatcher(true)
override fun match(arg: T?): Boolean {
return if(arg == null) {
false
} else {
try {
matchingFunc(arg)
} catch (a: AssertionError) {
false
}
}
}
override fun toString(): String = "matcher<${argumentType.simpleName}>()"
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:21 (13 by maintainers)
Top Results From Across the Web
Package assertk.assertions - GitHub Pages
Asserts that a collection contains a subset of items the same order, but may have other items in the list. corresponds. Link copied...
Read more >assertk test shouldn't pass (nested alls / any ?) - Stack Overflow
I made a typo with assert 2 and extracted the key instead of the value. When I realised that, I couldn't figure out...
Read more >Lua 5.2 Reference Manual
This type corresponds to a block of raw memory and has no pre-defined operations in Lua, except assignment and identity test. However, by...
Read more >The Glasgow Haskell Compiler User's Guide, Version 4.08
<majordomo@haskell.org>, with a message body (not header) like this: ... If used in conjunction with -cpp, the output is the code blocks of...
Read more >Lua 5.2 Reference Manual - Lua.org
Do not confuse Lua threads with operating-system threads. ... which can take appropriate measures (such as printing an error message).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We may need to revert this change. One unintended consequence is that in cases when multiple calls are made to the same mock, this will fail when matching the first one…
Test that succeeded before 12.3.1:
now fails…
Meanwhile, you can obviously build your own snapshot from master 😃