1

I have a number of microservices that share some common behaviors, which I've defined in some common .feature files.

Each microservice has a different root path, and 1 or more custom attributes.

I'd like to be able to test them with one karate invocation, in order to take advantage of the parallel execution that karate provides.

My first thought was to make a simple 'wrapper' feature file for each microservice, which would:

  1. define the root path, and any custom attributes, and
  2. call the common feature files.

So, the wrapper feature file for microservice1 looked like this:

Feature: microservice1 service

Background:
    * def authLevelCde = "ACL_FORE_DEFAULT"
    * def serviceName = "microservice1"

Scenario: Common CRU Tests
    * call read('common-cru.feature')

Scenario: Common Error Tests
    * call read('common-errors.feature')

I made multiple 'wrapper' feature files like the one above, each for a different microservice, each with it's own unique 'serviceName', and some with additional unique attributes which the common feature files were constructed to use when and as appropriate.

I could then invoke karate on one or more microservice wrapper feature files, like this:

java -cp ../karate-1.3.0/karate.jar:.. com.intuit.karate.Main fldfin.feature fore.feature

That works, but has 2 drawbacks:

  1. in each such 'wrapper' feature file, i have to explicitly call each 'common' feature file - i.e. I have to repeat what amounts to the definition of which features to use to test the microservice (though it is the same for all of my microservices);
  2. my common feature files have multiple Scenarios in them, but when called the way shown above in a 'wrapper' feature file, they appear as just one Scenario in the generated report.

Is there a way to do what I want without these drawbacks? Thanks!

Jon Detert
  • 51
  • 4
  • I realize I can use jvm properties on the cmd line to avoid using 'wrapper' feature files like I describe above, and avoid the 2 drawbacks cited above, with a command like this: ``` java -cp ../karate-1.3.0/karate.jar:.. com.intuit.karate.Main -DserviceName=aca-fore -DauthLevelCde=ACL_FORE_DEFAULT common-cru.feature common-errors.feature ``` but then I have a new set of drawbacks: 1. it's cumbersome to pass the custom bits on the command line (and where do I define what those bits are for each microservice?); 2. I can't make one invocation of karate run tests for multiple microservices. – Jon Detert Apr 24 '23 at 20:02
  • can you check if this answer gives you a solution: https://stackoverflow.com/a/60387907/143475 - which is to use a `Scenario Outline` to "loop" over a "hard-coded" list of microservices. if you really need a dynamic list, it is possible, refer: https://github.com/karatelabs/karate#dynamic-scenario-outline - or you can create different "wrapper" features. all that said, my personal (controversial) observations on "reuse" are here: https://stackoverflow.com/a/54126724/143475 – Peter Thomas Apr 25 '23 at 01:49

0 Answers0