I have written integration test which receives a xml document from queue, and create a object out of it which will be persisted in database. Now to be thorough in my test, I want to check all the fields that are populated by the xml i.e. around 20 fields. I wrote assert statement for each field.
assertTrue (payload.shipmentNo == object.shipmentNo)
assertTrue (payload.shipmentEMEA.location == object.shipmentLocationMap.get(SHIPMENT_EMEA.toString()))
assertTrue (payload.shipmentAMER.location == object.shipmentLocationMap.get(SHIPMENT_AMER.toString()))
assertTrue (payload.shipmentAPAC.location == object.shipmentLocationMap.get(SHIPMENT_APAC.toString()))
assertTrue (payload.shipmentVersion == object.shipmentVersion)
assertTrue (payload.shipmentSourceId == object.shipmentSourceId )
assertTrue (payload.noOfItemsInShipment == object.noOfItemsInShipment)
assertTrue (payload.shipmentName == object.shipmentName)
assertTrue (payload.shipmentDate == object.shipmentDate)
assertTrue (payload.shipmentOwnerID == String.valueOf(object.shipmentOwnerID))
assertTrue (payload.shipmentClass == object.shipmentClass)
assertTrue ('STARTED' == object.status)
But I am advised to use single assert statement in by testcase. I have been wondering how would I be able to do that, one way to achieve is to write an if block from which return true only if all the values match with the xml but in that case I loose the ability to know exactly which field is failing. Any ideas how can i achieve both things i.e. we have single assert + I get to know exactly which field failed.