Assertions Module
RECORDO
JsonAssertion
Asserts that the actual object is equal as JSON to the expected one stored in a file.
If the expected JSON file is missing, the actual value will be saved as expected.
All you need to do is verify the details, and the test will be ready.
If an assertion fails, the actual value will be saved in a new file for manual comparison.
JsonAssertion Parameters
.using(ObjectMapper mapper)
Sets the ObjectMapper to be used for JSON conversion.
.extensible(boolean value)
Sets whether the comparison should allow for additional properties in the expected JSON.
Defaults to false.
.withStrictOrder(boolean value)
Sets whether the order of elements in the JSON arrays should be strictly enforced.
Defaults to true.
.including(String... fields)
Specifies a list of fields to be included during comparison.
Fields can be specified with nested structures using dot notation (e.g., parent.name
, user.role.name
).
You can also use index for collections and arrays (e.g., children[0].id
, issues[0].tags[0].text
) or wildcard character *
to match any element (e.g., children[*].name
, issues[*].tags[*].text
).
.excluding(String... fields)
Specifies a list of fields to be excluded during comparison.
Fields can be specified with nested structures using dot notation (e.g., parent.name
, user.role.name
).
You can also use index for collections and arrays (e.g., children[0].id
, issues[0].tags[0].text
) or wildcard character *
to match any element (e.g., children[*].name
, issues[*].tags[*].text
).
Examples
CsvAssertion
Asserts that the CSV string matches the expected one from a file.
If the expected CSV file is missing, the actual value will be saved as expected.
You only need to verify them, and then the test will be ready.
If an assertion fails, the actual value will be saved for manual comparison.
CsvAssertion Parameters
withHeaders | With header line. Default value is |
withStrictOrder | Requires strict ordering of array elements. Default value is |
withColumnSeparator | Default value is |
withLineSeparator | Default value is |
Examples
Last updated