Testing / Karate Framework Interview questions
What is Karate's built-in mock server used for?
Karate's mock server lets a feature file define HTTP request/response behavior and serve it as a real, running HTTP endpoint, useful for testing a service in isolation from dependencies that are slow, unreliable, or simply not available in a given test environment.
Scenario: pathMatches('/users/{id}') && methodIs('get') * def id = pathParams.id * def user = { id: '#(id)', name: 'Mock User' } * karate.response.status = 200 * karate.response.body = user
Because mocks are written in the same Gherkin-based syntax as regular tests, they can be stateful (tracking data across requests within a test run), thread-safe, and run entirely locally, which makes them well suited to contract-style testing: running the same test suite once against a mock and once against the real service to check that both agree on behavior.
More Related questions...