This topic covers the Diff tool, which compares saved data with incoming data and reports differences in SOAtest and Virtualize.

Understanding Diff

With support for Binary, Text, XML, and JSON, the Diff tool is the current backbone of a best-practices regression testing solution.The Diff tool compares the data in its editor against the data that it receives from another tool's output or from another input that you specify and reports a failure when it finds a difference.

The Diff Project Configuration panel is divided into two main sections. The upper section contains general options. The bottom section contains the Regression Control, Ignored Differences, and Options tabs in which you can configure the options for comparing data in text, binary, JSON, and XML formats.

To customize the logic and data source usage for all Diff regression controls in a test suite:

  • Double-click the test suite’s Test Case Explorer node and modify the available options, which are described in Regression Options.

As with other tools, you can specify a data source for the tool if a source was added to the project. The data source for the Diff tool specifies the Data Source to be used for providing control values. For more information on Data Sources, see Parameterizing Tests with Data Sources, Variables, or Values from Other Tests.

Binary Diff Mode

Choose Binary from the Diff Mode menu to view differences for binary files.

Regression Control

This setting determines what data source values, file, or text is used as the "control" value (the value against which it will compare all subsequent results). Choose one of the following options.

Text Diff Mode

Choose Text from the Diff Mode menu to access the following configuration options for this mode.

Regression Controls

Determines what data source values, file, or text is used as the "control" value (the value against which it will compare all subsequent results). Choose one of the following options.

Ignored Differences

From the Ignored Differences tab of the Diff tool for Text mode, you can delete any ignored text differences by clicking the Delete button.

Options

The following options are available in the Options tab of the Diff tool for Text mode.

XML Diff Mode

Choose XML diff from the Diff Mode menu to access options for XML formats. XML mode parses XML files and compares them element by element and attribute by attribute (ignoring “ignorable” whitespace). The result of the comparison is expressed as an XML document. If you want to use this mode, make sure that both inputs are well-formed XML documents which have the same type of document element. 

Regression Control

Determines what data source values, file, or text is used as the "control" value (the value against which it will compare all subsequent results). The Regression Control settings include two graphical representations to configure XML messages.

Literal XML Regression Controls

The following options are available in the Regression Control tab of the Diff tool for Literal XML mode.

Form XML Regression Controls

When Form XML is selected as the regression control mode, the options in the Regression Control tab are divided into an XML View tree and XML configuration tabs.

The XML tree displays the literal XML as a tree with each tree node representing an element. The options for the tree in the Diff panel can be configured in the same fashion as the Form XML SOAP Envelope options of the SOAP Client tool. For more information, see Manipulating the XML View Tree.

The XML Configuration Tabs allow you to add, remove, and rename XML components. The options for the XML Configuration Tabs can be configured in the same fashion as the Form XML SOAP Envelope options of the SOAP Client tool. For more information, see Manipulating the XML Configuration Tabs.

XML Ignored Differences

From the Ignored Differences tab of the Diff tool for XML mode, you can Add and Modify XPath settings by clicking the appropriate buttons. For more information on configuring Ignored Differences, see Understanding XPaths.

XML Options

The following options are available in the Options tab of the Diff tool for XML mode.

Using VMTools

 VMTools is built into the product. No additional license is needed. If you select VMTools, you can specify the following options:

Under certain conditions, VMTools will fall back to a text-based diff. This can happen if the XML is very complex and produces an excessive number of differences or would take an excessive amount of time to complete.

If this occurs, one of the following messages will be printed to the Console view to explain what happened.

Did not run XML Diff, there are too many differences. Performing text mode diffing instead.

Did not run XML Diff, it did not finish within 30.0 secs. Performing text mode diffing instead.

The maximum time allowed to perform an XML diff before switching to text mode is the default timeout value specified in the preferences (go to Parasoft > Preferences > Misc and see the Default timeout (milliseconds) setting), but no higher than 120 seconds.

JSON Diff Mode Options

When JSON is selected from the Diff Mode menu of the Diff tool, the Regression Control and Ignored Differences options are available.

Regression Control

The following options are available in the Regression Control tab of the Diff tool for JSON mode.

Ignored Differences

From the Ignored Differences tab of the Diff tool for JSON mode, you can Add and Delete XPath settings by clicking the appropriate buttons.

Understanding XPaths

When the Diff tool is configured in the XML mode, any differences found between the actual value and the expected value are expressed in XPath. XPaths represent the position of an XML element and specifies where a difference occurred, the type of difference that occurred, and whether that difference was caused by a modification, an insertion, or a deletion.

You can determine which XPaths to ignore when running the Diff tool. You can choose to either ignore an entire XPath, or you can ignore a specific XPath operation such as a Content: Insert operation.

Ignoring XPaths is useful for ignoring transient values that would normally cause the regression test to fail. For example, the actual outcome may contain a timestamp value that is constantly changing. Since this value is never the same, it will more than likely not match the value you configure in the Diff tool, causing the test to fail. Therefore, you can specify the XPath of this value to be ignored so that the test will not fail.

There are three different ways you can set XPaths to Ignore:

Ignoring XPaths from the Quality Tasks View

When entering XPaths to ignore in the Diff tool, it is easier to right-click in the Quality Tasks view than manually entering the XPath position into the Diff tool GUI. XPath positions are displayed in tree form in the Quality Tasks view after a failed regression test:

To ignore an XPath from the Quality Tasks view after a failed regression test:

  1. Right-click the error and choose Ignore XPath. An Ignored XPath Settings dialog opens with the selected XPath automatically entered.
  2. Enable the options related to the XPath operations you would like to ignore. The following options are available:
  3. Click OK.

    The XPath you specified will now be ignored for any future test runs. In addition, the XPath you specified now appears in the Ignored Differences tab of the XML Mode in the Diff tool. To modify the XPath, see Modifying XPath Settings.

Manually Entering XPaths to Ignore

You can also manually type or paste an XPath to ignore into the Diff tool configuration panel.

To manually enter an XPath:

  1. Select the Ignored Differences tab within the Text, XML, or JSON mode of the Diff tool.
  2. Click Add. An empty field appears in the XPath column of the Ignored XPaths list. By default, the Settings column is automatically filled in with all XPath operations specified, meaning that the entire XPath you add will be ignored. To specify a single XPath operation to ignore, see Ignoring XPaths from the Form XML Tree.
  3. Enter an XPath position in the empty XPath field.
  4. To add additional XPaths, repeat steps 1 through 3.
  5. Click OK.

All XPaths added will be ignored in future runs of the modified regression test. For information on modifying ignored XPaths, see Modifying XPath Settings.

Ignoring XPaths from the Form XML Tree

You may also ignore XPaths directly from the Form XML tree within the Form XML tab by completing the following:

  1. Right-click an element node from the tree and choose Setup Ignored XPaths.
  2. Enable the appropriate options of the XPath operations you would like to ignore. The following options are available:
  3. Click OK.
    The selected element node now displays in gray in the Form XML tree. All XPath operations specified will be ignored in future runs of the modified regression test.
    To reset and no longer Ignore an XPath, right-click the Ignored XPath node and choose Remove Ignored XPath. The node will then display in black and will no longer be ignored.

Creating a Shared Ignored XPaths List

Diff tools can either have their own local, exclusive Ignored XPath settings, or they can reference a list of XPaths that can be used by other Diff tools. 

Modifying XPath Settings

By default, when you add an XPath to the Ignored Differences tab, all of the possible operations for that XPath appear in the Settings column. Since all of the possible operations for the XPath are specified by default, all of these operations will be ignored the next time the regression test is run. However, you can specify which operations are ignored, rather than having all of them ignored, by modifying the XPath settings.

To modify XPath settings:

  1. In the Ignored Differences tab, select the XPath you would like to modify and click Modify. The Ignored XPaths Settings dialog box opens.
  2. Enable the options related to the XPath operations you would like to ignore. The following options are available:
  3. Click OK.

All XPath operations specified will be ignored in future runs of the modified regression test.

Video Tutorial

In this video, you'll learn how to generate and update regression controls.