Tech Blog

Auto-generating BizUnit Test Cases

This post follows on from yesterday’s post: Creating
BizUnit Test Cases for comparing Xml Files

If you are using the XmlValidationStep/XmlValidationStepEx BizUnit
steps and using XPath validation, then it can be a pain to write all these XPathValidation
statements by hand.

So I wrote a utility to generate the XPath statements for you.
In fact, it generates the entire BizUnit Test Case for validating an Xml file.
Once it has been generated, all you have to do is:

a. Change the location to copy input files and look for output files (or change
completely if not using the File adapter)
b. Change the location/namespace of the Xsd file (if performing validation)
c. Edit the list of XPath statements to remove any which are not necessary.

Generating a Test Case can be performed:

  1. From the GUI (which will set the schema location in the Test Case if you have validated
    against that schema in the GUI)
  2. From the command line (useful for batch files and scripts)
  3. By right-clicking on an Xml file and choosing Generate BizUnit Test Case (assuming
    you have installed the reg file):

The utility (and installation/help files) can be found here:
DanSharp XmlViewer

Note: I also have a suggestion for an improved version of XmlValidationStep
you can find this here:
BizUnit:
XmlValidationStep using .NET 2.0 Schema Validation

This new version combines XmlValidationStep and XmlValidationStepEx into
a single step, allows you to not specify a namespace for the schema in the Test Case,
and uses the newer .NET 2.0 XmlReaderSettings mechanism
for validating schemas. I compile it into my own utility assembly and then refer to
it from a BizUnit TestCase via the assemblyPath attribute.

Back to Tech Blog