https://kotlinlang.org logo
#kotest
Title
# kotest
s

Sebastian Schuberth

11/28/2021, 10:06 AM
Yet one more thing: I just realized that
beforeTest()
in a
WordSpec
also gets called for the outer
WordSpecShouldContainerScope
. What can I use to just have something called for the contained actual tests, i.e. the
WordSpecTerminalScope
?
Looks like
beforeEach()
is the way to go...
s

sam

11/28/2021, 3:49 PM
beforeTest has always been "before every nested lambda". If you weren't seeing that before, sounds like a bug in 4.x with WordSpec
beforeEach is "before only leaf nodeS"
s

Sebastian Schuberth

11/28/2021, 3:51 PM
I believe the behavior was that like that before in Kotest 4, I just didn't realize until. as I was debugging other things...
As a side note, I believe the naming of the callback to be a bit unfortunate...
beforeEach()
sounds to me as if it would be called more often than
beforeTest()
, whereas the opposite is the case.
s

sam

11/28/2021, 3:52 PM
Yes the naming is shit
😄 1
beforeTest should be leaf's only but has existed since 1.0
As part of the docs work I am doing, I am going to add more pages on listeners as the docs don't do a good job of all the extensions atm
s

Sebastian Schuberth

11/28/2021, 3:54 PM
Yes, I agree calling
beforeTest()
on leaves only would be the more expected behavior.
s

sam

11/28/2021, 3:54 PM
beforeTest was meant to be deprecated in 5.0 due to this confusing behavior, because we added beforeAll as well which is the same thing.
But I decided not to deprecate it as I'm cautious about too many deprecations on something as fundamental as a test framework.
You could use
beforeAll
yourself, and forget
beforeTest
exists if you want.
s

Sebastian Schuberth

11/28/2021, 3:56 PM
Thanks, I'll probably do that.
What about a "soft deprecation" of
beforeTest()
?
s

sam

11/28/2021, 4:00 PM
I'm against deprecating anything that's used in 1000s of projects really. What I will do is just stop referencing beforeTest in docs and things, so over time it will fall out of use.