Hello. I have question about integration-testing o...
# ktor
f
Hello. I have question about integration-testing of ktor server. We have bigger ktor application which startup takes some time. For now, we use
withTestApplication {}
in our integration tests, but this causes that server has to start with each test. We started to have some performance issues, where test is executed in milliseconds, but server is starting for long time.. Do you have some experiences with starting server programatically, for example from
gradle
before running all tests? I found this solution https://stackoverflow.com/a/61246720 But not sure if it is correct approach.
a
Do you want to use a real or fake server for testing?
f
I was thinking about real server, for example using Docker container for it, but we have some test for different configurations and this would be issue with real server. So I am not sure which would be better for our use-case..
a
You can reduce a number of server startups by creating and destroying a fake server “before” and “after” each test class.
So you’d have a test class for each configuration.
f
Okay it makes sense. Maybe I can somehow create fake server also for more than single test class. There are only few use-cases which use different configurations. Do you think it would be possible?
a
The question is how you would share a server instance among different classes?
f
Maybe create something like
BaseTest
and inherit related tests from it.
a
That's how you can start a server for each class.
I mean to have a separate server instance for each test class.
f
I understand. Then maybe we can use server as global variable but probably that's not correct way
a
The root problem is that you don't control how test classes instantiated. Maybe, that can be solved on the test framework's side.
f
Maybe this solution could help https://stackoverflow.com/a/51556718
a
Yes, this can work if you can get an instance of the server in extended test classes.
Also, you can define top-level variable in a file and refer to it in each test.