Forum Discussion

tatty's avatar
tatty
New Contributor
17 years ago

Can you use an XML file (or perhaps Mock Test Response) as a giant assert?

Hi,

Is there some way to add a whole XML file as a giant assert for a test case? Is it somehow possible to do it using a Mock Test Response?

I am using SoapUI 2.5. Do I need to, perhaps, migrate to 3.0 or buy the Pro service?

3 Replies

  • tatty's avatar
    tatty
    New Contributor
    Well, I was actually hoping for something like a diff on the two files (expected xml result file and the actual result,) not a substring search of the "Simple Contains" assertion or a number of complex "XPath Match" assertion, because there are is a large number of elements returned by our service.
  • scdavis's avatar
    scdavis
    New Contributor
    You can't really produce a diff because the comparison for an XQuery or Xpath would be the entire expression that you supplied.  I have written something in groovy that may be useful for you though which does a tree-node as well as node-value comparison and allows for exceptions (i.e. timestamps in the response)  on a static XML file vs. dynamic response from the service.

    Email me if you're interested.

    texaggie95@yahoo.com

    Sean

    Here's a snippet:
          // If a node with kids is found, recursively process them by increasing the node depth.
          if(kids[x].children().size() > 0)
          {
            if(isIncludeNode( nodeMapExceptions, kids, x) )
            {
              data = xpath+" Node: "+kids[x].name()+" Value: *";
              list[ListIndex].add(data);
              //log.info(data);
              //log.info(list[ListIndex].size());
              iteratenode(kids[x],++depth,list,list.size(),xpath+"/"+kids[x].name());
              depth--;
            }
          }
          // If no kids, just record the data.
          else
          {
          // We'll exclude our exceptions here as long as they match the key value pairing we assigned
          //  These are FULL exceptions
            if(!(nodeMapExceptions.get(kids[x].name()) == kids[x].text().trim() ) && !(nodeMapExceptions.get(kids[x].name()) == "*" ) )
            {
              data = xpath+" Node: "+kids[x].name()+" Value: ";
              // These are VALUE exceptions