Testing / Karate Framework Interview questions
How do you troubleshoot a failing match assertion in Karate?
Karate's failure output for a match is usually specific enough to pinpoint the exact mismatched field, but a few systematic checks help when the cause isn't immediately obvious.
- Read the mismatch path and message carefully - Karate reports the JSON path of the specific field that didn't match, along with the actual vs. expected value, rather than just a generic failure.
- Check for type mismatches disguised as value mismatches - a numeric field returned as a string (or vice versa) fails an exact
matcheven if the printed values look identical; confirm the actual JSON type, not just the displayed value. - Check for extra or missing fields - if using exact
match ==, an API that added a new field (or omitted one) will fail even if every field the test cares about is correct; consider whethermatch containsis more appropriate. - Print the actual response before asserting - temporarily add
* print responseabove the failingmatchto see exactly what came back, rather than inferring it from the failure message alone. - Check for non-deterministic fields - timestamps, generated IDs, or ordering in arrays that vary between runs need a type marker (
#string,#number) or a sorted comparison rather than an exact literal value.
Most failing matches trace back to one of two root causes: the API's actual response shape doesn't match what the test assumed, or the test is asserting on a field that's legitimately variable and needed a type marker instead of an exact value.
More Related questions...