Assertion error but Expected same as Actual

2,108 views
Skip to first unread message

cl...@ninjavan.sg

unread,
Jan 18, 2016, 3:37:31 AM1/18/16
to REST assured
Hi everybody,

We got the following assertion error even though both the Expected and Actual values are same:

java.lang.AssertionError: 1 expectation failed.
JSON path inboundScan.result doesn't match.
Expected: [TRACKING_ID_NOT_FOUND]
     Actual: [TRACKING_ID_NOT_FOUND]

Below is the screenshot of the error:



We tried equalTo, equalToIgnoringWhiteSpace and equalToIgnoringCase with/without trim but it is still the same

Here is a snippet of the code:
.then()
            .body("inboundScan.result", equalTo("[TRACKING_ID_NOT_FOUND]".trim()));

For your information, we are using REST-assured 2.8.0 in MacOS X 10.11.2. Not sure if it helps

Please advise on how to resolve this. Thank you

Regards,
Clyde

Johan Haleby

unread,
Jan 18, 2016, 3:58:38 AM1/18/16
to rest-a...@googlegroups.com
What does your JSON/XML looks like?

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clyde Tan

unread,
Jan 18, 2016, 4:01:26 AM1/18/16
to REST assured
Hi Johan,

Here is the actual JSON printed in debug log:
[debug] - org.apache.http.wire -  >> "[{"scan":"InvalidID", "type":"SORTING_HUB", "hubId":1}]"

While the one in code is this:
.body("[{\"scan\":\"InvalidID\", \"type\":\"SORTING_HUB\", \"hubId\":1}]")

Regards,
Clyde

Johan Haleby

unread,
Jan 18, 2016, 4:09:03 AM1/18/16
to rest-a...@googlegroups.com
But that JSON document doesn't contain an attribute named "inboundScan"?

Clyde Tan

unread,
Jan 18, 2016, 4:10:41 AM1/18/16
to REST assured
Sorry, it's my fault

Here's the response JSON printed in debug log:

[debug] - org.apache.http.wire -  << "[{"inboundScan":{"id":18413,"createdAt":"2016-01-18T07:32:13Z","updatedAt":null,"deletedAt":null,"routeId":null,"scan":"InvalidID","location":null,"activeOrder":null,"activeRoute":null,"hubId":null,"type":"SORTING_HUB","result":"TRACKING_ID_NOT_FOUND"}}]"

Johan Haleby

unread,
Jan 18, 2016, 4:15:24 AM1/18/16
to rest-a...@googlegroups.com
Right, so the object your extracting is in a list so you can't use equalTo on the object itself. Use the hasItems matcher instead.

Clyde Tan

unread,
Jan 18, 2016, 4:47:19 AM1/18/16
to REST assured
Thank you Johan for pointing out the expected behaviour
Reply all
Reply to author
Forward
0 new messages