Question

I am using NUnit to write a test for a class that knows how to serialize itself to XML. The class has lots of properties so the XML fragment produced by the function I'm testing might be very long even with the default state of a new object.

When I run the test in the NUnit test runner and I've purposefully broken the expected returned XML, the test runner only shows a truncated version of the expected and actual string returned from the function that serializes the object to XML. Such as:

MyProject.MyTests.CanCreateObjectAndEdit:
  Expected string length 525 but was 1485. Strings differ at index 509.
  Expected: "...ffer="False" IsThing="False" /></MyObject>"
  But was:  "...ffer="False" IsThing="False" /><MySubObject ItemID="60..."
  --------------------------------------------^

Is there any way to get NUnit to return the entire expected and actual string? I have NUnit 2.6.3 (the latest release) and I am using the NUnit x86 GUI test runner.

My current workaround is to create a console app, copy the code out of the test, run it and print the output to a debug window, and then paste that output back into my test.

Était-ce utile?

La solution

Almost every Assertion method (i.e. Assert.AreEquals) takes a "message" parameter as a third argument.

It is printed only on test failures and it is intended to provide useful information to diagnose a test failure. I think it is exactly what you need.

Hope it helps.

Autres conseils

(With apologies for any transcription errors in the code below: I was testing this on a remote computer without copy/paste)

I tested the message parameter as suggested by Manuel.

    [Test]
    public void LongTest()
    {
        string s1 = new string('.', 1000);
        string s1 = new string('.', 500) + "+" + new string('.', 500);
        Assert.That(s1, Is.EqualTo(s2));
    }

and got the equivalent result to the one in the question: Truncated strings

Changing the Assert to

        Assert.That(s1, Is.EqualTo(s2), s1 + "\r\n\r\n" + s2);

changed the result to Full strings, but not fully visible which is possibly less than helpful, especially when the tooltip comes up showing you the entire thing. However, you can right-click on that area in the GUI runner and Copy it, and you do indeed get the whole text copied to the clipboard.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top