If you are doing a lot of unit or acceptance testing, you've probably have been using
FluentAssertions library (if not, give it a try!). This library presents a very good alternative to NUnit's Assert class (or equivalent unit test framework you are using). However, this are some caveats. One of them is that the ShouldBeEquivalent() extension method is
case-sensitive when comparing string (and there is no AssertionOptions to do that). However, if you use the Should() extension method, it is
case-insensitive. Putting it in simply terms:
[Test]
public void ThisWayItsCaseInsenstive()
{
var foo = "XPTO";
var bar = "xpto";
foo.Should().BeEquivalentTo(bar);
}
[Test]
[ExpectedException(typeof(AssertionException))]
public void ThisWayItsNot()
{
var foo = "XPTO";
var bar = "xpto";
foo.ShouldBeEquivalentTo(bar);
}
Yes, I know it's
documented, but it's
not obvious, which is a very
unfortunate design decision.
No comments:
Post a Comment