Ok... `beforeTest` and `afterTest` works... but wh...
# kotest
d
Ok...
beforeTest
and
afterTest
works... but what's the difference? It sounds from the docs that
beforeEach
should be called before each test case with the type
Test
,
should
isn't a
Test
?
w
Perhaps you need to set a different
isolationMode
to have the behavior you expect?
d
Maybe... but I put all the code inside the
should
, so that shouldn't really affect this... I'm just having trouble understanding the difference between the various lifecycle stages...
w
Me too, and I don’t use
beforeTest
and
afterTest
much really, so I mostly wanted to mention isolation mode in case you didn’t know that the default is somewhat confusing for JUnit users (as each spec is by default only instantiated once? I think) Anyway we use listeners sparingly and since we’re using isolationMode#perLeaf, we can just rely on before/afterSpec for mostly junit-like behavior
d
It seems like
Copy code
IsolationMode.SingleInstance
is the default..., thanks for the remark! I still need listeners for testcontainers though, and it's really puzzling how when a test is run by itself, it works, whereas in the whole suite, that same test fails...
w
Setting isolation mode to
perLeaf
should make the tests mostly independent, unless you’re sharing some statics. Or the listeners aren’t ran as you expect, but I’m not that familiar with them. Perhaps if you post a sample spec with simple listeners with prints and when you’d expect them to run but they don’t, someone will point you towards a solution 🙂
d
Thanks! I finally managed to sort things out, your little pointer got rid of a problem that was hiding a problem in the actual test code... I guess I'll be using
perLeaf
until I manage to sort out the repercussions of the other modes...
👍 1