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.
MSTest, hem VSTest hem de Microsoft.Testing.Platform (MTP)ile test çalıştırmayı destekler. MTP desteği, 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) testleri çalıştırabilen MSTest çalıştırıcısı tarafından desteklenir. MSTest çalıştırıcısı doğrudan MSTest test projelerinize eklenmiştir ve testlerinizi çalıştırmak için vstest.console veya dotnet test gibi başka uygulama bağımlılıklarına ihtiyaç yoktur. Ancak, dotnet testkullanarak testlerinizi yine de çalıştırabilirsiniz.
MSTest çalıştırıcısı açık kaynaktır ve Microsoft.Testing.Platform kitaplığında oluşturulur.
Microsoft.Testing.Platform kodu microsoft/testfx GitHub deposunda bulabilirsiniz. MSTest çalıştırıcısı MSTest in 3.2.0 veya daha sonraki sürümlerle birlikte gelir.
MSTest projesinde Microsoft.Testing.Platform'u etkinleştirme
Proje yapılandırmanızı ve projeyi güncelleştirmeyi büyük ölçüde basitleştirdiğinden ve platformun sürümleri (Microsoft.Testing.Platform) ve uzantılarının düzgün bir şekilde hizalanmasını sağladığından mstest SDK kullanmanız önerilir.
MSTest SDKkullandığınızda, varsayılan olarak Microsoft.Testing.Platform'u kullanmaya kabul edilirsiniz.
<Project Sdk="MSTest.Sdk/3.8.2">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Alternatif olarak, proje dosyanıza EnableMSTestRunner özelliğini ekleyip, OutputType'i Exe olarak ayarlayarak MSTest çalıştırıcısını etkinleştirebilirsiniz. Ayrıca MSTest 3.2.0 veya daha yeni bir sürüm kullandığınızdan emin olmanız gerekir. Kullanılabilir en son MSTest sürümüne güncelleştirmenizi kesinlikle öneririz.
Aşağıdaki örnek proje dosyasını göz önünde bulundurun:
<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>
Bahşiş
Çözümünüzdeki tüm test projelerinin MSTest çalıştırıcısını kullandığından emin olmak için, tek tek proje dosyaları yerine EnableMSTestRunner dosyasında TestingPlatformDotnetTestSupport ve özelliklerini ayarlayın.
Yapılandırmalar ve filtreler
.runsettings
Microsoft.Testing.Platform, runsettings ayarlarını --settingskomut satırı seçeneği aracılığıyla destekler. Desteklenen MSTest girdilerinin tam listesi için MSTest: Runsettings'i yapılandırma bölümüne bakın. Aşağıdaki komutlar çeşitli kullanım örneklerini gösterir.
kullanarak dotnet run:
dotnet run --project Contoso.MyTests -- --settings config.runsettings
kullanarak dotnet exec:
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
Test filtresi
Komut satırı seçeneğini kullanarak test filtresini sorunsuz bir şekilde sağlayabilirsiniz --filter. Aşağıdaki komutlarda bazı örnekler gösterilmektedir.
kullanarak dotnet run:
dotnet run --project Contoso.MyTests -- --filter "FullyQualifiedName~UnitTest1|TestCategory=CategoryA"
kullanarak dotnet exec:
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"