Deploying microservice to be tested within the test

1.8k views Asked by At

Maybe this is not possible to do generically in a test framework but

I would like to be able to deploy the microservice I am testing within the test itself. I have looked at Citrus, RestAssured, and Karate and listened to countless talks and read countless blogs but I never see how to do this first stage. It always seems to be the case that there is an assumption that the microservice is pre-deployed.

3

There are 3 answers

3
Peter Thomas On

2 points:

The karate-demo is a Spring Boot example that is deployed by the JUnit test-runner. Here is the code that starts the server.

If you have any requirements beyond these, I'd be happy to hear them. One of the things we would like to implement is a built-in server-side mocking framework - think embedded wiremock: but with the ease of Karate's DSL. But no concrete timeline yet.

EDIT: Karate has mocking now: https://github.com/intuit/karate/tree/master/karate-netty

1
Christoph Deppisch On

Honestly it depends on how your microservice is deployed and which infrastructure you are targeting on. I prefer to integrate the deployment into the Maven build as Maven provides pre- and post-integration-test phases.

In case you can use Kubernetes or Docker I would recommend integrating the deployment with fabric8 maven plugins (fabric8-maven-plugin, docker-maven-plugin). That would automatically create/start/stop the Docker container deployment within the Maven build.

In case you can use Spring boot the official maven plugin can do so in the same way.

Another possibility would be to use build pipelines. Where the continuous build with Jenkins for example would deploy the system under test first and then execute the tests in a pipeline.

I personally prefer to always separate deployment and testing tasks. In case you really want to do a deployment within your test Citrus as a framework is able to start/stop Docker containers and/or Kubernetes pods within the test. Citrus can also integrate with before/after test suite phases for these deployment tasks.

0
djangofan On

I found a way to do it using docker-compose.

https://github.com/djangofan/karate-test-prime-example

Basically, make a docker-compose.yml that runs your service container and then also runs e2e tests after a call to wait-for-it.sh.