다음을 통해 공유


MSTest의 Microsoft.Testing.Platform 지원(MSTest Runner)

MSTest는 VSTest 및 MTP(Microsoft.Testing.Platform)둘 다로 테스트 실행을 지원합니다. MTP에 대한 지원은 모든 컨텍스트(예: CI(연속 통합) 파이프라인, CLI, Visual Studio 테스트 탐색기 및 VS Code 텍스트 탐색기)에서 테스트를 실행할 수 있는 MSTest Runner를 통해 지원됩니다. MSTest 실행기는 MSTest 테스트 프로젝트에 직접 포함되며 테스트를 실행하는 데 필요한 vstest.console 또는 dotnet test같은 다른 앱에 대한 종속성이 없습니다. 그러나 dotnet test사용하여 테스트를 계속 실행할 수 있습니다.

MSTest Runner는 오픈 소스이며 Microsoft.Testing.Platform 라이브러리를 기반으로 합니다. Microsoft.Testing.Platform GitHub 리포지토리에서 코드를 찾을 수 있습니다. MSTest 실행기는 MSTest in 3.2.0 이상의 버전과 함께 제공됩니다.

MSTest 프로젝트에서 Microsoft.Testing.Platform 사용

프로젝트 구성 및 프로젝트 업데이트가 크게 간소화되고 플랫폼 버전(Microsoft.Testing.Platform)과 해당 확장의 적절한 맞춤이 보장되므로 MSTest SDK 사용하는 것이 좋습니다.

MSTest SDK사용하는 경우 기본적으로 Microsoft.Testing.Platform을 사용하도록 옵트인됩니다.

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

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

</Project>

또는 프로젝트 파일에서 EnableMSTestRunner 속성을 추가하고 OutputTypeExe로 설정하여 MSTest 실행기를 사용하도록 설정할 수 있습니다. 또한 MSTest 3.2.0 이상을 사용하고 있는지 확인해야 합니다. 사용 가능한 최신 MSTest 버전으로 업데이트하는 것이 좋습니다.

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

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

  <PropertyGroup>
    <!-- Enable Microsoft.Testing.Platform, this is an opt-in feature -->
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>

    <!--
      Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
      For more information, visit https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-integration-dotnet-test#show-failure-per-test
      -->
    <TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>

    <OutputType>Exe</OutputType>

    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </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
      Starting with 3.8, it also includes:
          Microsoft.Testing.Extensions.TrxReport
          Microsoft.Testing.Extensions.CodeCoverage
    -->
    <PackageReference Include="MSTest" Version="3.8.0" />

    <!--
      Coverlet collector isn't compatible with Microsoft.Testing.Platform, 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>

솔루션의 모든 테스트 프로젝트에서 MSTest runner를 사용하도록 하려면 개별 프로젝트 파일 대신 EnableMSTestRunner 파일에서 TestingPlatformDotnetTestSupport 속성을 설정합니다.

구성 및 필터

.runsettings

Microsoft.Testing.Platform은 명령줄 옵션 를 통해 --settings을 지원합니다. 지원되는 MSTest 항목의 전체 목록은 MSTest 구성: 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를 원활하게 제공할 수 있습니다. 다음 명령은 몇 가지 예를 보여 줍니다.

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"