Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
NUnit hem VSTest hem de Microsoft.Testing.Platform (MTP)ile test çalıştırmayı destekler. MTP desteği, testleri tüm bağlamlarda (örneğin, sürekli tümleştirme (CI) işlem hatları, CLI, Visual Studio Test Gezgini ve VS Code Metin Gezgini) çalıştırabilen NUnit çalıştırıcısı tarafından desteklenir. NUnit çalıştırıcısı doğrudan NUnit test projelerinize eklenir ve testlerinizi çalıştırmak için gereken vstest.console veya dotnet testgibi başka uygulama bağımlılığı yoktur. Ancak, dotnet testkullanarak testlerinizi yine de çalıştırabilirsiniz.
NUnit çalıştırıcısı açık kaynaktır ve Microsoft.Testing.Platformüzerinde oluşturulur.
Microsoft.Testing.Platform kodu microsoft/testfx GitHub deposunda bulabilirsiniz. NUnit çalıştırıcısı, NUnit3TestAdapter sürüm 5.0 veya üzeri sürümlerde desteklenir. Daha fazla bilgi için bkz. NUnit ve Microsoft.Testing.Platform
NUnit projesinde NUnit çalıştırıcısını etkinleştirme
Proje dosyanızdaki EnableNUnitRunner özelliğini ekleyip OutputType'i Exe olarak ayarlayarak NUnit çalıştırıcısını etkinleştirebilirsiniz. Ayrıca, NUnit3TestAdapter sürüm 5.0 veya üzerini kullandığınızdan da emin olmanız gerekir.
Bahşiş
Çözümünüzdeki tüm test projelerinin NUnit çalıştırıcısını kullandığından emin olmak için, tek tek proje dosyaları yerine EnableNUnitRunner dosyasında TestingPlatformDotnetTestSupport ve özelliklerini ayarlayın.
Aşağıdaki örnek proje dosyasını göz önünde bulundurun:
<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/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>
<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>
Yapılandırmalar ve filtreler
.runsettings
NUnit çalıştırıcısı, destekler. Aşağıdaki komutlarda örnekler gösterilmektedir.
dotnet runkullanma:
dotnet run --project Contoso.MyTests -- --settings config.runsettings
dotnet execkullanma:
dotnet exec Contoso.MyTests.dll --settings config.runsettings
-veya-
dotnet Contoso.MyTests.dll --settings config.runsettings
Yürütülebilir dosyayı kullanma:
Contoso.MyTests.exe --settings config.runsettings
Testler filtresi
Komut satırı seçeneği 'yi kullanarak test --filter'i sorunsuz bir şekilde kullanabilirsiniz. Aşağıdaki komutlarda bazı örnekler gösterilmektedir.
dotnet runkullanma:
dotnet run --project Contoso.MyTests -- --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"
dotnet execkullanma:
dotnet exec Contoso.MyTests.dll --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"
-veya-
dotnet Contoso.MyTests.dll --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"
Yürütülebilir dosyayı kullanma:
Contoso.MyTests.exe --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"