1

New to service virtualization but while I was researching I noticed that Karate has some support for it too. Since I'm already using it, I'm curious to see if it would fit the need. I am trying to test my API A which calls upon another API B, with some retry logic. The request doesn't change, but B might send a response body with an error message or a success message. The intent is to retry x times until we see a success of fail overall. So, the question is how can i mock the response of B in this test? The request being made by A ofcourse would remain the same.

user1111871
  • 137
  • 1
  • 12

1 Answers1

0

Karate can easily do this. You can set up a "global" variable in your mock that will keep a count of the number of times called. The rest is "normal" Karate.

You should read the docs. Ask a separate specific question if needed: https://stackoverflow.com/a/61374079/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Possibly dumb question while I am reading the documentation. Api A would have within its configs/properties/code somewhere the path to hit B right? So, how is that being routed to the Karate mock for B. In the documentation I see we can create the mock server and mock responses. I'm curious how when I am testing A /doSomething (which internally calls actual Api B /doSomethingForA) would the mock B be substituted in? – user1111871 Aug 20 '20 at 20:15
  • @user1111871 https://stackoverflow.com/a/61414022/143475 – Peter Thomas Aug 21 '20 at 02:37
  • 1
    Ok. Starting to understand it much better now. Thank you much. I'd been reading the https://intuit.github.io/karate/karate-netty/ documentation and kept feeling like i was missing this info and wasn't sure if I had understood it right – user1111871 Aug 21 '20 at 05:57
  • @user1111871 I recommend the ZIP release example, it will take you just 5 minutes to see how it works: https://github.com/intuit/karate/wiki/ZIP-Release#api-mocks – Peter Thomas Aug 21 '20 at 06:23
  • Will do that. Thank you - with a CI/CD env where the deployment of the app happens in some location/pod- and the next stage afterward being a validation stage running separate from the pod - they're completely disjoint - so not seeing how the intercept will happen. But been really into trying to learn this and build more of our tests with karate. Quite awesome stuff – user1111871 Aug 21 '20 at 07:19
  • @user1111871 refactor to run on one node or pre-define the port to use, you'll have to figure what works – Peter Thomas Aug 21 '20 at 07:20