Testing / Karate Framework Interview questions
What is the difference between match contains and match contains only?
match contains checks that the actual value includes at least the specified elements or keys, allowing additional elements the assertion doesn't mention. match contains only is stricter: it requires the actual value to contain exactly the specified elements, no extras, but without caring about their order (which is the key difference from a plain exact-equality match == on an array).
* def tags = ['urgent', 'billing', 'reviewed'] # passes: 'urgent' and 'billing' are present, extra 'reviewed' is fine * match tags contains ['urgent', 'billing'] # fails: array has an extra element ('reviewed') beyond what's listed * match tags contains only ['urgent', 'billing'] # passes: same elements, order doesn't matter for contains only * match tags contains only ['reviewed', 'billing', 'urgent']
Use contains when the test only cares that certain elements are present and doesn't want to be broken by additional, unrelated elements appearing. Use contains only when the full set of elements matters, but their specific order in the array doesn't, which is common for things like unordered tag lists or sets of returned IDs.
More Related questions...