Edit on GitHub

xUnit2011 Warning

Do not use empty collection check

Cause

A violation of this rule occurs when Assert.Collection 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

Use Assert.Empty instead.

Examples

Violates

[Fact]
public void ExampleMethod()
{
    IEnumerable<string> result = GetItems();

    Assert.Collection(result);
}

Does not violate

[Fact]
public void ExampleMethod()
{
    IEnumerable<string> result = GetItems();

    Assert.Empty(result);
}

How to suppress violations

#pragma warning disable xUnit2011 // Do not use empty collection check
#pragma warning restore xUnit2011 // Do not use empty collection check
Copyright © 2017 .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit.analyzers.