New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Constraint resolve #25

GKotfis opened this Issue Apr 5, 2018 · 2 comments


None yet
2 participants

GKotfis commented Apr 5, 2018

I think there is a problem with resolving constraint. Especially 'Not' constraints. Following test failed with message:
XML with XPath root/node Expected: <empty> But was: "someValue".
XML with XPath root/node Expected string length 3 but was 9. Strings differ at index 0. Expected: "ups" But was: "someValue" -----------^

It should be Expected: <not empty> for the first assertions and pass for second.

public void XPathTest()
    var xml = @"<root><node>someValue</node></root>";

    Assert.That(xml, EvaluateXPathConstraint.HasXPath("root/node", Is.Not.Empty));
    Assert.That(xml, EvaluateXPathConstraint.HasXPath("root/node", Is.Not.EqualTo("ups")));

I've made a simple change by adding Resolve() to valueConstraint. In this cases, it helps. I'm not familiar with custom constraints in NUnit and don't know if it's appropriate solution that cover all cases.

public static EvaluateXPathConstraint HasXPath(string xPath, IConstraint valueConstraint)
    return new EvaluateXPathConstraint(xPath, valueConstraint.Resolve());

@bodewig bodewig added the constraints label Apr 5, 2018


This comment has been minimized.


bodewig commented Apr 5, 2018

To be honest it's been some time since I last looked into writing constraints. There have already been bugs when the constraints have been combined with others - see 95b7519 for example.

It may take a few days before I find time to look into it, many thanks for the simple test case.

bodewig added a commit to xmlunit/xmlunit that referenced this issue Apr 13, 2018

@bodewig bodewig added this to the 2.6.0 milestone Apr 13, 2018

bodewig added a commit that referenced this issue Apr 13, 2018

@bodewig bodewig closed this in 53cbb5a Apr 13, 2018


This comment has been minimized.


bodewig commented Apr 13, 2018

Many thanks for the report. While writing the tests for this I discovered the messages where also misleading for all of the NUnit3 constraints (and some of the NUnit2 constraints) when they were negated.

@bodewig bodewig added the bug label Apr 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment