Build/Test Issues

NUnit Assert Not Failing Test (string comparison)

Started by SethO on 5,255 views

Found this issue late yesterday when comparing serialized Newtonsoft.JObjects. Can replicate with the following test:

[Test]
public void ThisTestShouldFailButDoesNot()
{
    const string expected = "{\"string\":\"e82fdc14-9fc6-4acc-86ef-95743a54b7ea\",\"bool\":true,\"int\":46}";
    const string actual = "{}";
    Assert.AreEqual(expected, actual);
}


If I debug the code, I will throw an AssertionException on the assertion line, as expected. However, the NCrunch runner reports the test as green/passing.

If any other code is placed after the "Assert.That()" line, it will not execute, and it will not have a green dot on any of the lines.

This happens on both v2.17 and v2.18.0.3.

Edit: Using NUnit v3

Edited

I did some further digging and got it down to this:
namespace ConsoleApplication1
{
    [TestFixture]
    public class Test
    {
        [Test]
        public void ThisTestShouldFailButDoesNot()
        {
            Assert.AreEqual("a", "{");
        }
    }
}


This should fail and throws an AssertionException, but nCrunch shows the test as passing and puts a green dot next to it.

Post a reply

Log in to reply.