Edit on GitHub

xUnit2011   v2 v3   Warning

Do not use empty collection check

Cause

A violation of this rule occurs when Assert.Collection or Assert.CollectionAsync is used without element inspectors to check for an empty collection.

Reason for rule

There are specialized assertions for checking collection sizes.

How to fix violations

To fix a violation of this rule, you can:

Examples

Violates

using Xunit;

public class xUnit2011
{
    [Fact]
    public void TestMethod()
    {
        var result = new[] { 1 };

        Assert.Collection(result);
    }
}

Does not violate

using Xunit;

public class xUnit2011
{
    [Fact]
    public void TestMethod()
    {
        var result = new[] { 1 };

        Assert.Empty(result);
    }
}
using Xunit;

public class xUnit2011
{
    [Fact]
    public void TestMethod()
    {
        var result = new[] { 1 };

        Assert.Collection(
            result,
            value => Assert.Equal(1, value)
        );
    }
}
Copyright © .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit/tree/gh-pages.