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. : , , . :
- xunit.console TeamCity, ?
- xunit.console ? xunit.runner.console .NET.
- , , .NET?
- ? , , , , .
- ?
- TeamCity?
TeamCity, 5 , .NET:
(1): “ xunit.console?”:
.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, . :
, xunit.console . . (solution), :
, 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:
: . :
- 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, ..)
(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- . :
(2) . , -, :
xunit.console NuGet- xunit.runner.console .NET Framework ( .NET Framework 4.72), . 2 xunit.console .
- , .NET Core .NET 5+.
- dotCover .
- xunit.console Xunit Runner Executable.
, - , , , , .NET Framework.
dotnet test
.NET Runner test , .NET TeamCity. :
:
: 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, .