Giter Club home page Giter Club logo

xmlunit.net's Introduction

XMLUnit.NET 2.x

Build Status XMLUnit.NET 2.x

XMLUnit is a library that supports testing XML output in several ways.

Some goals for XMLUnit 2.x:

  • create .NET and Java versions that are compatible in design while trying to be idiomatic for each platform
  • remove all static configuration (the old XMLUnit class setter methods)
  • focus on the parts that are useful for testing
    • XPath
    • (Schema) validation
    • comparisons
  • be independent of any test framework

We are in the process of finalizing the API for XMLUnit 2.x.

Help Wanted!

If you are looking for something to work on, we've compiled a list of things that should be done before XMLUnit 2.0 can be released.

Please see the contributing guide for details on how to contribute.

Examples

These are some really small examples, more is to come in the user guide

Comparing Two Documents

ISource control = Input.FromFile("test-data/good.xml").Build();
ISource test = Input.FromByteArray(CreateTestDocument()).Build();
IDifferenceEngine diff = new DOMDifferenceEngine();
diff.DifferenceListener += (comparison, outcome) => {
            Assert.Fail("found a difference: {}", comparison);
        };
diff.Compare(control, test);

or using the fluent builder API

Diff d = DiffBuilder.Compare(Input.FromFile("test-data/good.xml"))
             .WithTest(CreateTestDocument()).Build();
Assert.IsFalse(d.HasDifferences());

or using the CompareConstraint

Assert.That(CreateTestDocument(), CompareConstraint.IsIdenticalTo(Input.FromFile("test-data/good.xml")));

Asserting an XPath Value

ISource source = Input.FromString("<foo>bar</foo>").Build();
IXPathEngine xpath = new XPathEngine();
IEnumerable<XmlNode> allMatches = xpath.SelectNodes("/foo", source);
string content = xpath.evaluate("/foo/text()", source);

Validating a Document Against an XML Schema

Validator v = Validator.ForLanguage(Languages.W3C_XML_SCHEMA_NS_URI);
v.SchemaSources = new ISource[] {
        Input.FromUri("http://example.com/some.xsd").Build(),
        Input.FromFile("local.xsd").Build()
    };
ValidationResult result = v.ValidateInstance(Input.FromDocument(CreateDocument()).Build());
bool valid = result.Valid;
IEnumerable<ValidationProblem> problems = result.Problems;

or using ValidationConstraint

Assert.That(CreateDocument(),
            new ValidationConstraint(Input.FromFile("local.xsd")));

Requirements

XMLUnit requires .NET 3.5 (it is known to work and actually is developed on Mono 4).

The core library provides all functionality needed to test XML output and hasn't got any dependencies. It uses NUnit 2.x for its own tests. The core library is complemented by NUnit constraints.

Checking out XMLUnit.NET

XMLUnit.NET uses a git submodule for test resources it shares with XMLUnit for Java. You can either clone this repository using git clone --recursive or run git submodule update --init after inside your fresh working copy after cloning normally.

If you have checked out a working copy before we added the submodule, you'll need to run git submodule update --init once.

Building

XMLUnit for .NET builds using NAnt, run nant -projecthelp for the available targets, but mainly you want to run

$ nant

in order to compile core and constraints and build the assemblies.

$ nant test

executes the NUnit tests.

xmlunit.net's People

Contributors

bodewig avatar joephayes avatar brabenetz avatar

Watchers

Ty Moodley avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.