This might be more of a Junit question, but maybe ...
# kotest
d
This might be more of a Junit question, but maybe kotest has something to help me too. I use Property Testing and I test on some graph-like inputs. Let's say I also have some function which can convert those graphs into a pretty printed text or a png file or a graphviz-dot file. These graphs might be quite big and so having them printed out would mess up output pretty badly. So when the test fails I'd like to see something like
Test failed for /tmp/file1.png (shrunk from /tmp/file2.png)
(links would be clickable in IDE) I see no such mechanism to provide "custom artifacts" either in JUnit or in Kotest, am I right? I found only junit xml reports which looks quite off-putting for me :)
s
So do you just want to do something when a test fails ?
t
For a similar situation I convert long multiline text into a list of strings, and then compare each string in the list. It works, but not perfect.
d
Yep, I want to perform an IO side-effect so to speak. And another thing I'd like is to have it somehow integrated into the output (file name I could click to open etc), but that's a separate thing I guess.
s
Would a test listener do what you want
d
I will check that out thanks! I saw them in the documentation, didn't dig in.
Ok, test listeners look like the step in the right direction, but I still somehow have to pass them the "big-complex-object" (graph) for the listener to serialize it. I've tried to use "withClue(graph)", hoping that it'll somehow end up in the assert-exception instance, but it is just being toString-ed. Any advice perhaps? Basically imagine that I do this test:
Copy code
graph.someProperty shouldBe 3
and when it fails I want to print whole graph to the file inside a test listener.
s
you could capture the exception, use it, then re-throw
try { graph.someProperty shouldBe 3 } catch { use(graph) }
and wrap that in your own function
d
Thank you! Will try this approach, I can invent some nice wrapper function indeed.