요구 사항에 따라 MSTest 테스트를 실행하는 방법은 여러 가지가 있습니다. IDE(예: Visual Studio, Visual Studio Code, JetBrains Rider), 명령줄 또는 CI 서비스(예: GitHub Actions 또는 Azure DevOps)에서 테스트를 실행할 수 있습니다.
지금까지 MSTest는 모든 컨텍스트에서 테스트를 실행하기 위해 VSTest 에 의존했지만 버전 3.2.0부터 MSTest에는 자체 테스트 실행기를 가지고 있습니다. 이 새로운 실행기는 VSTest보다 더 가볍고 빠르며, MSTest 테스트를 실행하는 데 권장되는 방법입니다.
VSTest 및 Microsoft.Testing.Platform(MTP)
MSTest는 VSTest 및 MTP(Microsoft.Testing.Platform)를 사용하여 테스트를 실행할 수 있습니다. MTP에 대한 지원은 모든 컨텍스트(예: CI(연속 통합) 파이프라인, CLI, Visual Studio 테스트 탐색기 및 VS Code 텍스트 탐색기)에서 테스트를 실행할 수 있는 MSTest Runner를 통해 지원됩니다. MSTest Runner는 MSTest 테스트 프로젝트에 직접 포함되며 테스트를 실행하는 데 필요한 다른 앱 종속성(예: vstest.console 또는 dotnet test)이 없습니다. 그러나 을 사용하여 dotnet test테스트를 계속 실행할 수 있습니다.
MSTest Runner는 오픈 소스이며 Microsoft.Testing.Platform 라이브러리를 기반으로 개발되었습니다.
Microsoft.Testing.Platform GitHub 리포지토리에서 코드를 찾을 수 있습니다. MSTest Runner는 MSTest in 3.2.0 또는 그 이상의 버전과 함께 제공됩니다.
MSTest 프로젝트에서 Microsoft.Testing.Platform 사용
MSTest SDK를 사용하면 프로젝트 구성 및 프로젝트 업데이트가 크게 간소화되고 플랫폼 버전(Microsoft.Testing.Platform)과 해당 확장이 적절하게 정렬되도록 하는 것이 좋습니다.
사용하는 MSTest SDK경우 기본적으로 Microsoft.Testing.Platform을 사용하도록 옵트인됩니다.
<Project Sdk="MSTest.Sdk/4.1.0">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
프로젝트 파일에 EnableMSTestRunner 속성을 추가하고 OutputType을 Exe로 설정하여 MSTest Runner를 활성화할 수 있습니다. 또한 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>net10.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="4.1.0" />
</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"
참고하십시오
.NET