MSTest 실행기 개요

MSTest 실행기는 모든 컨텍스트(예: CI(연속 통합) 파이프라인, CLI, Visual Studio 테스트 탐색기, VS Code 텍스트 탐색기)에서 테스트를 실행하기 위한 VSTest의 가볍고 이식 가능한 대안입니다. MSTest 실행기는 MSTest 테스트 프로젝트에 직접 포함되며 테스트를 실행하는 데 필요한 vstest.console 또는 dotnet test같은 다른 앱에 대한 종속성이 없습니다.

MSTest 실행기는 오픈 소스이며 Microsoft.Testing.Platform 라이브러리를 기반으로 합니다. Microsoft.Testing.Platform 코드를 microsoft/testfx GitHub 레포지토리에서 찾을 수 있습니다. MSTest 실행기는 MSTest in 3.2.0-preview.23623.1 이후 버전과 번들로 제공됩니다.

MSTest 프로젝트에서 MSTest 실행기 사용

프로젝트 구성, 프로젝트 업데이트를 크게 간소화하고 플랫폼 버전(MSTest 실행기)과 해당 확장을 적절하게 맞춤할 수 있도록 MSTest SDK를 사용하는 것이 좋습니다.

MSTest SDK를 사용하면 기본적으로 MSTest 실행기를 사용하도록 선택됩니다.

<Project Sdk="MSTest.Sdk/3.3.1">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

또는 프로젝트 파일에서 EnableMSTestRunner 속성을 추가하고 OutputTypeExe로 설정하여 MSTest 실행기를 사용하도록 설정할 수 있습니다. 또한 MSTest 3.2.0-preview.23623.1 이상을 사용하고 있는지 확인해야 합니다.

다음 프로젝트 파일 예를 고려해보세요.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <!-- Enable the MSTest runner, this is an opt-in feature -->
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <OutputType>Exe</OutputType>

    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>

  <ItemGroup>
    <!--
      MSTest meta package is the recommended way to reference MSTest.
      It's equivalent to referencing:
          Microsoft.NET.Test.Sdk
          MSTest.TestAdapter
          MSTest.TestFramework
          MSTest.Analyzers
    -->
    <PackageReference Include="MSTest" Version="3.2.0" />

    <!--
      Coverlet collector isn't compatible with MSTest runner, you can
      either switch to Microsoft CodeCoverage (as shown below),
      or switch to be using coverlet global tool
      https://github.com/coverlet-coverage/coverlet#net-global-tool-guide-suffers-from-possible-known-issue
    -->
    <PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage"
                      Version="17.10.1" />
  </ItemGroup>

</Project>

구성 및 필터

.runsettings

MSTest 실행기는 명령줄 옵션 --settings를 통해 runsettings를 지원합니다. 다음 명령은 예를 보여 줍니다.

dotnet run사용:

dotnet run --project Contoso.MyTests -- --settings config.runsettings

dotnet exec사용:

dotnet exec Contoso.MyTests.dll --settings config.runsettings

또는

dotnet Contoso.MyTests.dll --settings config.runsettings

실행 파일 사용:

Contoso.MyTests.exe --settings config.runsettings

테스트 필터

명령줄 옵션 --filter를 사용하여 테스트 filter를 원활하게 제공할 수 있습니다. 다음 명령은 몇 가지 예를 보여 줍니다.

dotnet run사용:

dotnet run --project Contoso.MyTests -- --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"

dotnet exec사용:

dotnet exec Contoso.MyTests.dll --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"

또는

dotnet Contoso.MyTests.dll --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"

실행 파일 사용:

Contoso.MyTests.exe --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"