Do not use equality check to check for collection size.
A violation of this rule occurs when Assert.Equals
or Assert.NotEquals
are used to check if a collection has 0 or 1 elements.
There are specialized assertions for checking collection sizes.
Use Assert.Empty
, Assert.NotEmpty
, or Assert.Single
instead.
using System.Linq;
using Xunit;
public class xUnit2013
{
[Fact]
public void TestMethod()
{
var result = new[] { "Hello" };
Assert.Equal(1, result.Count());
}
}
using Xunit;
public class xUnit2013
{
[Fact]
public void TestMethod()
{
var result = new[] { "Hello" };
Assert.Single(result);
}
}