nunit: NullReferenceException using Is.EqualTo on two unequal strings

I’m writing some tests and wanted to test the equality of two strings. I didn’t realise until runtime that they would be unequal. I expected the Assert to fail but not with a null reference exception.

Text comparison as been shortened for ease of reading but the result is the same.

       'string errorText = ScenarioContext.Current.Get<FlightSearchPod>().errorOnScreen;

        string requiredText = "You can only book one infant per adult online.";

        Assert.That(errorText, Does.Contain(requiredText));`

At runtime errorText = “Oops!\r\nYou can only book one infant per adult online.”.

If I change requiredText to “Oops!\r\nYou can only book one infant per adult online.” it works without an exception. This Exception is only thrown on v3.6.0, If I try the same Assert on earlier versions it works fine so I’m trying to determine if it’s a feature or an issue.

I can get around the issue by using Does.Contain but have been asked by my organisation to see if we can identify the cause of this unexpected exception.

Let me know if I need to provide any more information, I’m fairly new to automation testing.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Looks very much like #1965 and #1952 stack traces. I’ll check it out in the morning.