equalTo
Only matches if the input string is exactly equal to the expected value.
binaryEqualTo
Like equalTo
but compares bytes rather than strings. Useful when you need to match
e.g. an uploaded image.
matches
Matches the input string against a Java style regular expression.
doesNotMatch
The negative of matches
. Will match if the incoming value does not match the regular expression.
contains
Matches if the input string contains the expected value.
doesNotContain
The negative of contains
. Will match if the input string does not contain the expected value.
equalToJson
Matches if the input string is valid JSON and is semantically equal to the expected value.
This is often a better choice than equalTo
when dealing with JSON as it will ignore
differences in whitespace, and it is optionally possible to ignore array orderings
and extra object attributes. It also provides the concept of placeholders, allowing
you to selectively ignore or merely constrain specific JSON elements.
The underlying implementation for equalToJson
is supplied by
JSONUnit.
You can learn more about working with JSON in the Matching JSON article.
matchesJsonPath
Tests the input JSON string against a JSONPath expression, and returns a match if
one or more elements are returned. No match will be returned if the input is not valid
JSON.
The actual JSONPath evaluation is performed by the Java JSONPath implementation.
equalToXml
Matches if the input string is valid XML and is semantically equal to the expected value.
Like with matchesJsonPath
this ignores differences in whitespace and supports placeholders
so that specific element values can be ignored.
The underlying implementation for equalToXml
is supplied by
XMLUnit.
You can learn more about working with XML in the Matching XML article.