If I wanted to start a server and then run tests a...
# gradle
s
If I wanted to start a server and then run tests against it for CI, all in the same Gradle command, would that be possible?
m
What kind of server?
OkHttp MockWebServer is especially made for that if you want to test network code: https://github.com/square/okhttp/tree/master/mockwebserver
c
i think the most usual pattern is to spin up the server that you test from your test code.
3
s
I’m talking about a Java Server. i.e. Ktor or Vertx or Spring. These are things people do with
yarn
or
npm
all the time.
c
if you do it in the test code you can run it all in a single jvm and thats faster
2
s
Good suggestion, but I can’t do that in this case. I’d like the same tests to be portable, and usable across all environments / production. If I tie the tests to the server in the current process, I lose that ability
c
why not set an env variable
TEST_SERVER=<http://staging.blah.com>
if you want to run against an existing server, and if the env variable is empty the suite spins up the server itself.
v
To me it sounds like you are after a Shared Build Service. This can then spin up the server (or like christoph suggested use an existing one configured throuhg gradle properties or environment variables or whatever) if the task that needs it is going to be executed and can tear it down cleanly afterwards.
s
Shared Build Service seems like exactly what I want
it’s not clear to me how I should be starting the server though from the Build Service
v
What exactly is not clear / are you struggling with?