File Comparators

Plain File Comparator

Create an instance of the comparator by providing the file paths of the two files that are going to be compared, for example:

var comparator = PlainFileComparator.Create(myFilepath1, myFilepath2);

// Performing a custom assertion over the comparator instance.
comparator.Compare().Validate(result => result);

To be able to use the custom assertions over the comparators, you will need to import the Mobilize.QualityMate.Common.Extensions namespace.

Additionally the comparator can generate a verbose output that will help you to identify differences found within the files. Example:

comparator.ResultsInOutput = true; // This setting is "false" by default.
comparator.ResultType = PlainComparisonResult.PrettyHtml;
comparator.Compare();

If the files have differences, the comparator will generate a file with the prefix plaindiff and extension .html with the results.

The comparators' default output path is within the TestOutput folder.

XML File Comparator

This comparator works similar to the Plain File Comparator because both are based in the same class. Here is an example:

var comparator = new XmlFileComparator(expectedXmlPath, actualXmlPath)
{
    ResultsInOutput = true,
    XPathsInDescriptions = true,
};
comparator.CompareExcludingNodesByXPath("/Document/Parents").Validate(result => result);
comparator.CompareNodesByXPath("//Name", "//Priority", "//Goods").Validate(result => !result);

Multiple validations over the same comparator instance will print the results into the same output file.

Last updated