Good morning. I have a problem migrating my small ...
# kotest
Good morning. I have a problem migrating my small integration test suite to Kotest. I have a custom
) that sets up Koin with Ktor’s `MockEngine`s and in-memory SqlDelight database. I have 3 test classes with 17 tests in total. If I run a single class, all of them pass with no problem, but if I run tests for the whole module, 2 out of 17 fail with
io.ktor.serialization.JsonConvertException: Illegal input
on a network request I wonder what could make the difference 🤔 I tried with different `IsolationMode`s
I have a convenience
object MockEngines
and in some tests I use
, so on Kotest this same modified engine is persisted across all the tests, thus my successive api request receive an unexpected Json, as I don't set any constraints on that handler for simplicity of the code
I gave up on Ktor's mockserver, I found everything needs to be done manually... I ended up using WireMock with a kotlin wrapper lib I found, it encourages to write better tests and constraints.
I don’t have experience with WireMock, but I found Ktor-mock excellent! The MockEngine is not very versatile, but with a small trick, I’ve been able to: • Have “static” and isolated `MockEngine`s, like
,etc, that can be reused easily for Unit tests • Merge multiple `MockEngine`s into a single one, to use for Integration tests • Add dynamic handlers to override a single request If you’re interested, here are my utils; still need some refactor, specially regarding
where there is some code duplicated from below, but it does its job
Nice! I tried starting with something like that, but I found it much easier to use this:
You get proper logs of requests/responses, simulation of network failures and lots more features of a more advanced mock server.
It's based on:
Thanks! Looks cool!