3

Is there any good way to get Karate tests to test a Spring-Boot microservice in the "integration-test" phase of a Maven build? What I mean is: is there an anti-pattern/workaround that works well OR am I out of luck because this was an afterthought of the Karate development?

Facts I have gathered so far:

  1. It says here: "the surefire plugin is not hardcoded into Karate" Is there a way to run Karate test during maven's integration test phase?

  2. Running Karate tests in context of maven-failsafe-plugin does not work at all. Easy to reproduce on my test project url below. Two problems foremost:

    1. When running from maven-failsafe, Karate will generate .txt and .html files but does not generate .json Cucumber output files.
    2. Therefore, you can get no HTML report from the cucumber-reporting plugin (which I require)
  3. I created a project to demonstrate these facts: https://github.com/djangofan/karate-api-sample

  4. Running integration tests requires that I start Spring Boot before the test suite and then stop the spring boot server afterwards. Maven SureFire does not have this capability BUT the maven failsafe plugin does: the maven build helper plugin has a pre-integration-test hook for it. Limited only by Maven surefire, I am out of luck.

  5. I see an example in the karate/karate-demo project of starting the spring boot server from code. This is not easy to accomplish when I am trying to test a web service that is already established. Is this my only option: to use surefire with a class filter and code to bootstrap?

  6. Given no good answer, I will just revert to using cucumber-java + resteasy, which I am pretty sure will work with maven failsafe: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/cucumber.html

djangofan
  • 28,471
  • 61
  • 196
  • 289

1 Answers1

0

First, this is not Karate.js not sure where that came from :)

When running from maven-failsafe, Karate will generate .txt and .html files but does not generate .json Cucumber output files.

Sorry, cannot replicate.

For failsafe, just use the naming conventions and it will work, e.g. **/IT*.java

Maven SureFire does not have this capability BUT the maven failsafe plugin does:

So use failsafe as mentioned above. If you are not able to do that, please change your project to demonstrate the issue and we promise to fix it. Also refer these instructions: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Given no good answer, I will just revert to using cucumber-java + resteasy

That is of course your choice. At least in my (biased :) opinion you will miss all the JSON assertion value that Karate adds, and the parallel execution + aggregation of reports. I am sure you will help as far as possible so that we can make the experience better for all who need this solution - but else, hey - no worries :P

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Ok, will do. I am surprised you couldn't reproduce with the project I already created though. All you need to do is replace the string 'surefire' with 'failsafe' in the pom.xml and then run it, and you would reproduce (at least partially). I can create a new project that reproduces to a more detailed extent. – djangofan Nov 28 '19 at 18:48
  • @djangofan make sure you follow the instructions closely: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Nov 29 '19 at 00:37
  • 1
    I tried it. Turns out that I cannot be done and it is a limitation of Maven, not Karate. https://stackoverflow.com/questions/10138559/howto-add-another-test-source-folder-to-maven-and-compile-it-to-a-separate-folde/40917384 . Here is my test project to prove it out: https://github.com/djangofan/spring-boot-hello . Thanks for leading me down what appears to have been the correct path to discover the limitation. Using Gradle would likely solve my issue but that is not an option on my project. If I use Karate for "separated integration tests", I need a separate mvn test module. – djangofan Dec 01 '19 at 00:31
  • @djangofan many thanks for the update and the links, this will help others – Peter Thomas Dec 01 '19 at 01:50
  • I fixed my repo link (in above comment). It is now publicly visible. – djangofan Dec 03 '19 at 21:22
  • 1
    I finally got this working and it greatly reduces the amount of boilerplate code I need in my Karate tests. Basically, I wire up Spring boot to talk to DB and JMS and then my Karate tests use that as a proxy to the actual system. This means my Karate tests are therefore 100% HTTP calls without any imported Java classes. – djangofan Aug 26 '20 at 15:14