Microsoft. NUnit(NUnit Runner)의 MTP(Testing.Platform) 지원

팁

실행기를 사용하도록 설정하기 전에 테스트 플랫폼 개요를 참조하세요.

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

NUnit 실행기는 오픈 소스 있으며 MTP 위에 빌드됩니다. Microsoft.Testing.Platform GitHub 리포지토리에서 코드를 찾을 수 있습니다. NUnit Runner는 NUnit3TestAdapter 버전 5.0 이상에서 지원됩니다. 자세한 내용은 NUnit 및 MTP 참조하세요.

NUnit 프로젝트에서 NUnit runner 활성화

EnableNUnitRunner 속성을 추가하고 project 파일에서 OutputTypeExe 설정하여 NUnit runner를 사용하도록 설정할 수 있습니다. 또한 NUnit3TestAdapter 버전 5.0 이상 버전을 사용하고 있는지 확인해야 합니다.

팁

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

다음 예제 project 파일을 고려합니다.

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

  <PropertyGroup>
    <!-- Enable the NUnit runner, this is an opt-in feature -->
    <EnableNUnitRunner>true</EnableNUnitRunner>
    <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/unit-testing-with-dotnet-test#show-failure-per-test
      -->
    <TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>

    <OutputType>Exe</OutputType>

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

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
    <PackageReference Include="NUnit" Version="4.3.2" />
    <PackageReference Include="NUnit.Analyzers" Version="4.6.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />

    <!--
      Coverlet collector isn't compatible with NUnit 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

NUnit Runner는 명령줄 옵션 을 통해 --settings을 지원합니다. 다음 명령은 예제를 보여 줍니다.

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"