You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm looking to ease development of testing code using Step Verifier and checking for Exception Types and messages to ensure the appropriate error was raised.
// This is how the existing test code looks
myService.myFunction().test()
.verifyErrorMatches { it is MyException && it.message == "My Message" }
// And this is a more Kotlin idiomatic code could look like
myService.myFunction().test()
.verifyErrorMatches<MyException> { it.message == "My Message" }
While the above is not dissimilar it does seperate out the typing from the predicate, which adds to clarity IMHO. Also note the it in the second example is typed to MyException so you can test properties with out further casting.
Desired solution
This is the functions which would implement this
inline fun <reified T : Throwable> LastStep.expectErrorMatches(crossinline predicate: (T)->Boolean = {true}): StepVerifier =
expectErrorMatches { it is T && predicate(it) }
inline fun <reified T : Throwable> LastStep.verifyErrorMatches(crossinline predicate: (T)->Boolean = {true}): Duration =
verifyErrorMatches { it is T && predicate(it) }
Considered alternatives
Haven't consider other alternatives, except verifyErrorMessage() expectErrorMessage() but these dont allow checking of type. That I am aware, so dont offer the full ability of xxxErrorMatches()
The text was updated successfully, but these errors were encountered:
Motivation
I'm looking to ease development of testing code using Step Verifier and checking for Exception Types and messages to ensure the appropriate error was raised.
While the above is not dissimilar it does seperate out the typing from the predicate, which adds to clarity IMHO. Also note the
it
in the second example is typed toMyException
so you can test properties with out further casting.Desired solution
This is the functions which would implement this
Considered alternatives
Haven't consider other alternatives, except verifyErrorMessage() expectErrorMessage() but these dont allow checking of type. That I am aware, so dont offer the full ability of xxxErrorMatches()
The text was updated successfully, but these errors were encountered: