Skip to content

toftware/TeamCity.VSTest.TestAdapter

 
 

Repository files navigation

Test Adapter for

Provides the TeamCity integration with test frameworks via the Visual Studio Test Platform or VSTest IDE tools.

Supported platforms:

  • Visual Studio Test Platform
  • VSTest Console version 12+

Visual Studio Test Platform

Presently, Visual Studio has an open and extensible test platform with tests written using various test frameworks and run using a variety of adapters. The Test Platform, from its vantage, resolves the lifecycle of the test into a series of stages – two of which are writing and running the test – with the goal of providing extensibility at each stage.

For each test project:

  • Add a NuGet reference to the Visual Studio Test Platform.

    dotnet add package Microsoft.NET.Test.Sdk
    
  • Add NuGet references to NuGet packages of the selected test framework and coresponding test adapter which supports Visual Studio Test Platform. For example:

    dotnet add package MSTest.TestFramework   
    dotnet add package MSTest.TestAdapter
    
    dotnet add package xunit   
    dotnet add package xunit.runner.visualstudio
    
    dotnet add package NUnit   
    dotnet add package NUnit3TestAdapter
    
    dotnet add package DevTeam.TestFramework   
    dotnet add package DevTeam.TestAdapter
    

    or others.

Alternatively to two steps above, you could create the a test project from the command line using the specified template:

dotnet new mstest

or

dotnet new xunit
  • To support the TeamCity integration add a NuGet reference to the TeamCity Test Adapter to turn on the TeamCity integration.

    dotnet add package TeamCity.VSTest.TestAdapter
    

Thus, the final project file could look like the following:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>    
    <TargetFrameworks>net45;netcoreapp1.0;netcoreapp2.0</TargetFrameworks>    
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
    <PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
    <PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.6" />    
  </ItemGroup>  
</Project>

VSTest Console

  • To support the TeamCity integration, add a NuGet reference to the TeamCity Test Adapter

  • To run tests from the command line, use additional command line arguments: /TestAdapterPath:., /Logger:teamcity

    • The first argument points to the path where the runner can find the assembly of the TeamCity logger (the directory of the testing aseembly).

    • The second argument points to the TeamCity service messages logger.

For example:

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" dotNet.XUnit.Tests.dll /Logger:teamcity /TestAdapterPath:.

VSTest extensions

  • Download the custom logger

  • Extract the contents of the downloaded archive on the agent machine:

    • for VisualStudio 2017 update 5 onwards - to PROGRAM_FILES(x86)\Microsoft Visual Studio\2017<Edition>\Common7\IDE\Extensions\TestPlatform\Extensions

    • for VisualStudio 2017 till update 4 - to PROGRAM_FILES(x86)\Microsoft Visual Studio\2017<Edition>\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions

    • for VisualStudio 2015 - to PROGRAM_FILES\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions

    • for VisualStudio 2013 - to PROGRAM_FILES\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions

    • for VisualStudio 2012 - to PROGRAM_FILES\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions

  • Check that the custom logger was installed correctly by executing vstest.console.exe /ListLoggers in the console on the agent machine. If the logger was installed correctly, you will see the logger with FriendlyName TeamCity listed: TeamCity.VSTest.TestLogger.TeamCityTestLogger URI: logger://teamcity

See more details in the Wiki.

See the article for details on how to create tests using the Visual Studio Test Platform.

DOCKER CONTAINER

To run tests from within a Docker container that is hosted on a machine running the TeamCity agent, the container must have an environment variable set to a/any value. Example...

ENV TEAMCITY_PROJECT_NAME=My Project
RUN dotnet test

License

It is under the Apache License.

Contributors

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.7%
  • Batchfile 0.3%