xunit

xUnit.net is a free, open source, community-focused unit testing tool for .NET.

  • documentation @github 9
  • Comparing xUnit.net to other frameworks 1
  • Using xUnit with ASP.NET Core, 2 blog 2016
  • Unit testing C# in .NET Core using dotnet test and xUnit 3 mslearn
  • Getting Started with xUnit.net
    v3 .NET or .NET Framework with the .NET SDK command line 6
    v2 .NET Core with Visual Studio 5
    v2 .NET Framework with Visual Studio 4.
  • End to end testing angular js apps with XUnit and Protractor.Net 7 2016
  • Assert.ThrowsAsync 10
  • Creating parameterised tests in xUnit with InlineData, ClassData and MemberData 11, 2017
  • xUnit Theory: Working With InlineData, MemberData, ClassData 12, 2017
  • Introduction to integration testing with xUnit and TestServer in ASP.NET Core 13, 2016
  • Capturing Output 14
  • Shared Context between Tests 15

Deadlock when using parallelization and blocking on async code

VS runner hangs on Run All #611

  public static object ApiVversionControllerNameGet(this IGeneratedAPI operations, string version) { 
    return operations.ApiVversionGetAsync(version).GetAwaiter().GetResult(); 
  }

Resolution was to:

update test runner related packages in the HLD template

  <package id="xunit" version="2.3.1" targetFramework="net462" />
  <package id="xunit.abstractions" version="2.0.1" targetFramework="net462" />
  <package id="xunit.analyzers" version="0.7.0" targetFramework="net462" />
  <package id="xunit.assert" version="2.3.1" targetFramework="net462" />
  <package id="xunit.core" version="2.3.1" targetFramework="net462" />
  <package id="xunit.extensibility.core" version="2.3.1" targetFramework="net462" />
  <package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net462" />
  <package id="xunit.runner.visualstudio" version="2.2.0" targetFramework="net462" developmentDependency="true" />

Configure xUnit to not participate in parallelization with other assemblies.
Tests in the same test collection will be run sequentially against each other, but tests in different test collections will be run in parallel against each other.

All parallelization within this test assembly is disabled.

  <!--https://xunit.github.io/docs/configuring-with-xml.html-->
  <appSettings>
    <add key="xunit.appDomain" value="ifAvailable" />
    <add key="xunit.diagnosticMessages" value="true" />
    <add key="xunit.methodDisplay" value="classAndMethod" />
    <add key="xunit.parallelizeTestCollections" value="false" />
    <add key="xunit.parallelizeAssembly" value="false" />
    <add key="xunit.preEnumerateTheories" value="true" />
    <add key="xunit.shadowCopy" value="true" />
    <add key="longRunningTestSeconds" value="10" />
  </appSettings>

Classes with a sensible number of tests have been isolated into collections, collection is Xunit.CollectionAttribute:

    [Collection("Some Collection")]
    [Trait("Controller", "Controller Name")]
    [Trait("Client", "AutoRest")]
    public class SomeControllerTests {...}

For a .NET Core project, a xUnit configuration would have been done via a xunit.runner.json file in the test project root.

{
  "appDomain": "ifAvailable",
  "diagnosticMessages": true,
  "methodDisplay": "classAndMethod",
  "parallelizeTestCollections": true,
  "internalDiagnosticMessages": true,
  "parallelizeAssembly": true,
  "preEnumerateTheories": true,
  "shadowCopy": true
}