xUnit testing in TeamCity

Microsoft is actively developing its open source projects, such as ASP.NET Core or MSBuild . Along with this, the xUnit test framework is gaining popularity , which is used in them for unit testing. In this article, we will look at several ways to run xUnit tests for continuous project integration using TeamCity .







Sample build configurations can be found on this TeamCity demo server , and the source code is in this repository : Lib is the code of the application under test, and Lib.Tests is the project with tests. Both of these projects target the .NET versions of net472 and netcoreapp2.1 .







To support xUnit, the test project has a NuGet dependency for the corresponding xunit package :







<PackageReference Include="xunit"/>









This meta package does not contain binaries, but adds several dependencies to the xunit.core , xunit.assert, and xunit.analyzers NuGet packages . This is the xUnit test API. Each test method in xUnit is marked with the [Fact] attribute for regular tests or [Theory] for parameterized tests. Usually, each tested module corresponds to its own test class with a set of test methods that check one or another logic. Each tested project has its own test project.







, TeamCity . , . TeamCity , . : , TeamCity .







xUnit console runner



, xunit.console, xunit.runner.console. : , , . :







  1. xunit.console TeamCity, ?
  2. xunit.console ? xunit.runner.console .NET.
  3. , , .NET?
  4. ? , , , , .
  5. ?
  6. TeamCity?


TeamCity, 5 , .NET:







image







(1): “ xunit.console?”:







image







.NET, xunit.runner.console Lib.Tests. 2 xunit.console TeamCity. , . xunit.console ? , NuGet-:





  • Windows: %userprofile%\.nuget\packages



  • Mac/Linux: ~/.nuget/packages





, , , TeamCity, . . , xunit.console, NUGET_PACKAGES %teamcity.build.checkoutDir%/packages. , NuGet- . packages, . :







image







, xunit.console . . (solution), :







image







, packages NuGet- , xunit.runner.console, Lib.Tests/bin/Debug – , .NET. Lib.Tests/bin/Debug/net472 , Lib.Tests/bin/Debug/netcoreapp2.1 .NET CoreApp 2.1 . , _JSON-_ , . 3 .NET CoreApp 2.1:







image







: . :







  • Lib.Tests/bin/Debug/net472
  • Lib.Tests/bin/Debug/netcoreapp2.1/publish


xunit.console :







  • packages/xunit.runner.console/**/net472/xunit.console.exe
  • packages/xunit.runner.console/**/netcoreapp1.0/xunit.console.dll


** – xunit.runner.console.







(1) (2) . (3) , .NET. , .NET , . , , PowerShell- TeamCity Kotlin DSL. (4) (5), , , , .NET, :





  • ,
  • xunit.console.dll _xunit.console.exe _ , (, Docker, ..)


.NET:





image







image







(6): “ TeamCity?”. xunit.console , _TEAMCITY_PROJECTNAME, TeamCity . xunit.console , TeamCity service messages.







, , . - , TeamCity Meta-Runner.







Meta-Runners Power Pack



TeamCity - Power Pack - xUnit.net-dotCover, xUnit- . :







image







(2) . , -, :







image







xunit.console NuGet- xunit.runner.console .NET Framework ( .NET Framework 4.72), . 2 xunit.console .







- xUnit.net-dotCover:







  • , .NET Core .NET 5+.
  • dotCover .
  • xunit.console Xunit Runner Executable.


, - , , , , .NET Framework.







dotnet test



.NET Runner test , .NET TeamCity. :







image







:







  • : xUnit, NUint . .







  • , .







  • .NET TargetFrameworks, Full .NET Framework, .NET Core .NET 5+.







  • Docker-.







  • - .









Visual Studio Rider dotnet new, , dotnet new xunit -o Lib.Tests, . "", , xunit, Microsoft.NET.Test.Sdk xunit.runner.visualstudio:







<PackageReference Include="Microsoft.NET.Test.Sdk"/>









<PackageReference Include="xunit.runner.visualstudio"/>









Microsoft.NET.Test.Sdk MSBuild, , : xunit.runner.visualstudio, Visual Studio Test Platform. , , NUnit – NUnit3TestAdapter, MSTest – MSTest.TestAdapter.







xUnit .







, ! TeamCity , . TeamCity .NET, .








All Articles