1

We have lot many vendors and not all have sandboxed environments made available to test integration.

I was looking to mock them and thus would host them myself, we are using karate extensively as our BDD tool.

  • How can multiple mock services be hosted using single project?(Multiple Feature files)
  • How can I achieve different hostname for different mock services?
  • Can it be used as a regular server running for long?

Similar question : Using mocks in Karate DSL feature file with stanalone run

Amit Vyas
  • 103
  • 2
  • 8

1 Answers1

1

How can multiple mock services be hosted using single project

Refer the answer you linked. Use Java code for the best way to start multiple mocks.

How can I achieve different hostname for different mock services?

Normally you change your services config to point to where the mock is running, typically localhost + : + portNumber - also refer the docs on using Karate as am HTTP proxy, and also search the net on modifying etc.hosts entry if needed.

Can it be used as a regular server running for long?

Keep in mind that Karate is a "mock" :) but if you don't keep adding data to what is in-memory it should be fine. No guarantees though :P

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Is there a way to host all mock services behind a single port? I am using ```FeatureServer server = FeatureServer.start(file, 9999, false, null);``` to start the server with Just one Mock. Want to add Multiple mocks and host them via single port. – Amit Vyas Mar 21 '19 at 17:24
  • 1
    @AmitVyas no that is not supported. sounds like you have over-engineered things. just combine all your endpoints into one feature file. personally I don't think trying to make mocks into a full fledged app-server framework (you are asking for routing) is a good idea – Peter Thomas Mar 22 '19 at 07:34
  • 1
    I am moving towards providing a single service which mocks all third parties for all e2e scenarios. Mocks stay live during testing only. I guess I'll be trying grpc mocks as well going forward. Not intended to use mocks as app server Config but holding multiple projects for mocks or hacks in current server starting logic doesn't need to happen if multiple mocks are supported. Mocks in karate are powerful, haven't seen a lot of people using it extensively. – Amit Vyas Mar 23 '19 at 09:18
  • 1
    @AmitVyas yes I'm surprised more people haven't realized how simple and powerful it is. I'm very clear that things need to be kept simple - which is why I'm against making the mocks more "fancy" - but if you have ideas (please be specific, ideally with code examples) I'm open to hearing them – Peter Thomas Mar 23 '19 at 14:21
  • I am writing all Scenarios in a Single Feature file which is becoming a little inconvenient as it is growing. So I was thinking if we can give a folder and all features files in there can be used as Mock endpoints. So I'll come back to Mocks again, there are lot of things I want to do especially intelligent recording, playback & my favourite part simulating different conditions which 3rd parties suffers from and are difficult to replicate. – Amit Vyas Mar 25 '19 at 15:20
  • Btw, I have to admit being guilty ;) , I was tempted lot many times to use Mocks as actual app server especially when persistence is just a call away (https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/dogs/dogs.feature) – Amit Vyas Mar 25 '19 at 15:20
  • @AmitVyas yes. contribute or provide examples :) what I worry about is the edge cases - e.g. what if the same end-point is in 2 mocks. personally I don't see a problem if you have started 3-4 mocks on different ports. you anyway need a mechanism to configure your consumers to use specific URL:PORTs – Peter Thomas Mar 25 '19 at 15:52