catching exceptions #58
Replies: 2 comments 3 replies
-
I like the idea, and I'll definitely think about if there's a good way to do it, but exceptions present an interesting challenge for 2 reasons:
One potential short term solution could be to go the
But this also introduces a support library which I've been trying to avoid. And it kind of introduces something which might not have a lot of longterm value if something more generic is introduced. Anyways, some ramblings on the idea. |
Beta Was this translation helpful? Give feedback.
-
@bnorm just for |
Beta Was this translation helpful? Give feedback.
-
I am trying out kotlin power assert in the test suite of failgood, and I'm currently using it for all my new tests as an experiment.
its great for asserting, but unit tests also need "safe traversal":
https://github.com/failgood/failgood/blob/5c8a0f527083e8bccce5e6dcba7eb7b648a63361/failgood/src/test/kotlin/failgood/functional/ErrorHandlingTest.kt#L46
here I am using assertNotNull:
but it would be much cooler if i could instead write the first line as
and power assert would wrap it with a try / catch and treat the exception just like a failed assertion, outputting the value of
suiteResult.failedContexts
.maybe the whole assertion part of the unit test could be wrapped in a block, lets call it
then
(from given/when/then)(or
each line in the then block is either an assertion or an assignment for navigation. and everything is treated as one big soft assert.
Beta Was this translation helpful? Give feedback.
All reactions