Problem: Time-consuming E2E testing of HTTP endpoints
E2E testing of HTTP endpoints can be time-consuming, especially when dealing with elaborate JSON or XML requests. You could of course use frameworks such as Postman, Rest-Assured or Spring MockMvc, but in turn they suffer from issues like tracking of changes, setup of the environment, maintenance of test data, or ease of test execution and the corresponding reporting.
Solution: The Karate Framework With Direct Support of JSON and XML
Example for End-to-End Tests with Karate
The following example checks an XML response where the order is irrelevant (you might compare the actual response from mocky.io with the expectation in the test).
Feature: jambit API
Scenario: Checking mission and motto collectively
Given url "http://www.mocky.io/v2/5bd9ab282f00005c0006d262" And header Accept = "application/xml" When method get Then status 200 And match response contains """ <jambit> <mission>100% Begeisterung</mission> <motto>Where innovation works</motto> </jambit> """
The following test suite defines the URL for subsequent test cases and then the parameterized test randomly checks three expectations.
Feature: Users API
Background: * url "https://jsonplaceholder.typicode.com/" Scenario Outline: Given user ID, validate company name Given path "users", <id> When method get Then status 200 And match response.company.name == "<companyName>" Examples: | id | companyName | | 1 | Romaguera-Crona | | 3 | Romaguera-Jacobson | | 7 | Johns Group |