4

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.

Brian Reinhold
  • 2,313
  • 3
  • 27
  • 46

3 Answers3

2

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.

Christoph Deppisch
  • 2,181
  • 1
  • 8
  • 13
  • 1
    Thanks Christoph. I have looked into the Jenkins pipeline options and it is raising my hopes that it will make test development easier. Need to have the service running in order to test! The downside right now is my unsure understanding of using Docker and Kubernetes on a Windows system. – Brian Reinhold Aug 31 '17 at 16:23
1

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Peter, thanks for your quick response. I have looked at Karate, Citrus, and RestAssured quite a bit in the last week (all of this kind of testing is new to me). Could I use the Karate framework to deploy a microservice that is not written in Java? I am not the developer of the microservices but I happen to know at this time it is Java and Spring with Spring Boot. As far as creating the mock services Hoverfly should work fine. My understanding is that Karate also works with Jenkins and Zappy (in order to report results in JIRA) – Brian Reinhold Aug 30 '17 at 14:05
  • @BrianReinhold - in theory you can use Java to call even native code - so it is up to how much you are willing to push the automation envelope :) as in the other answer, Docker is a popular way to bring up services + dependencies as part of a test bootstrap. You will like Karate's reports: https://twitter.com/KarateDSL/status/899671441221623809 – Peter Thomas Aug 30 '17 at 14:59
  • Peter I do see Docker a lot which is an agony for Windows people since VMs are involved. My major concern is also test development; what I want to avoid it the time to deploy the microservice which has its own embedded server in a VM just to develop the test. Somehow I cannot see how one can possibly avoid knowing the language the microservice is written in if one needs to build, locally run, and develop tests for that microservice in isolation (with all its mocks) and not take all day. By the way; I have no choice but to put the test results into JIRA. That is not my decision! – Brian Reinhold Aug 31 '17 at 09:17
1

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.

djangofan
  • 28,471
  • 61
  • 196
  • 289