views:

64

answers:

2

This is an interesting question I am sure a lot of people will benefit from knowing.

a typical web service will return a serialized complex data type for example:

<orgUnits>
 <orgUnit>
     <name>friendly name</orgUnit>
 </orgUnit>
 <orgUnit>
     <name>friendly name</orgUnit>
 </orgUnit>
</orgUnits>

The VS2008 unit testing seems to want to assert for an exact match of the return object, that is if the object (target and actual) are identical in terms of structure and content.

What I would like to do instead is assert only if the structure is fine, and no errors exist.

To perhaps simplify the matter, in the web service method, if any error occurs I throw a SOAPException.

1.Is there a way to test just based on the return status 2. Best case scenario would be to compare the doc trees for structural integrity of target and actual, and assert based on the structure being sound, and not the content.

Thanks in advance :)

+1  A: 

I think that this is a duplicate of http://stackoverflow.com/questions/1157859/wsdl-testing/1158019

In that answer I suggested SoapUI as a good tool to use

AutomatedTester
+1  A: 

An answer specific to your requirement would be to compare the serialized versions(to XML) of the object instead of the objects themselves.

Approach in your test case

  1. Lets say you are expecting a return like expected.xml from your webservice .
  2. Invoke service and get an actual Obj. Serialize that to an actual.xml.
  3. Compare actual.xml and expected.xml by using a library like xmldiff(compares structural /value changes at XML level).
  4. Based on the output of xmldiff determine whether the webservice passed the test.
Pradeep