I have a Spring Boot application with a service th...
# kotest
a
I have a Spring Boot application with a service that caches data, but Kotest isn’t wiping the cache between data-driven tests in an
afterEach{}
hook - should it? I thought that
withData()
would register a test case for each data element, and so
afterEach{}
would be triggered by the end of each
withData(...) {}
block
here’s the full test & application • Kotest 5.5.4 • Kotlin 1.7.21 • Spring Boot 2.7.5
e
what version of kotest-extensions-spring?
a
the latest, but I’ll check
1.1.2
e
Change lifecycle mode to Test (default one), root one only resets between root tests 🙂
a
same problem :/
e
Oh.. hmm.. I wonder if this is because Spring re-uses the context as long as it's not dirtied.
a
I’ve added some println statements in here. When I search the logs, I don’t see any
AFTER EACH
matches. So I don’t think the
afterEach {}
is triggered, which is strange
e
try adding
@DirtiesContext(ClassMode.AFTER_EACH_TEST_METHOD)
It should work. I made a PR to address this a while back. https://github.com/kotest/kotest-extensions-spring/pull/23
a
adding
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
works, but it makes the tests too slow
and I still don’t see
AFTER EACH
in the logs
e
hehe, of course.. hmm.. wonder if your
CustomRootSpec
is interfering
trying to replicate the issue in the kotest-examples-spring-webflux repo
a
cool, thanks
s
I don't think after each fires for dynamic tests
d
Your commit is only for afterTest and beforeTest, afterEach and beforeEach still only work for tests of type TEST (not Dynamic), that still needs a PR I think
This was discussed in this channel recently, you might have to browse back a bit
e
Ah, shit. 🙂 Thanks..
d
Don't know if there has been an actual PR for it but the problem was identified
e
So easy workaround for now would be to use
afterTest
, if that works for you.
Looks like someone else also got bit by this: https://github.com/kotest/kotest/issues/3290
a
using
afterAny {}
seems to work
thanks for your help all
e