Kirill Zhukov
03/05/2024, 11:30 PMshould
operator does not print stacktrace on a failure? I have a matcher like this:
fun beEnabled(buttonModel: ButtonModel) =
Matcher<ButtonModel> { model ->
MatcherResult(
buttonModel.isEnabled,
{ "expected $model to be enabled" },
{ "expected $model to not be enabled" }
)
}
fun ButtonModel.shouldBeEnabled(): ButtonModel =
apply {
this should beEnabled(this)
}
On failure shouldBeEnabled
throws assertion error without full stacktrace which makes it hard to figure out where that assertion failed exactly:
java.lang.AssertionError: [REDACTED]
expected ButtonModel(text=Continue, isEnabled=false, isLoading=false, leadingIcon=null, treatment=Primary, size=Footer, testTag=null, onClick=StandardClick(onClick=() -> kotlin.Unit)) to be enabled
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
When I change shouldBeEnabled
implementation to this, I get the full stacktrace on failure, am I implementing a custom matcher wrong?
fun ButtonModel.shouldBeEnabled(): ButtonModel =
apply {
this.isEnabled.shouldBeTrue()
}
reformator
03/06/2024, 5:20 PM