-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Globalization; | ||
using System.Runtime.InteropServices; | ||
Check failure on line 5 in test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs
|
||
using System.Text.RegularExpressions; | ||
|
||
using Microsoft.Testing.Platform.Acceptance.IntegrationTests; | ||
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; | ||
using Microsoft.Testing.Platform.Helpers; | ||
|
||
using Polly.Caching; | ||
Check failure on line 12 in test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs
|
||
|
||
namespace MSTest.Acceptance.IntegrationTests; | ||
|
||
[TestGroup] | ||
public sealed class MaxFailedTestsExtensionTests : AcceptanceTestBase | ||
{ | ||
private const string AssetName = nameof(MaxFailedTestsExtensionTests); | ||
private readonly TestAssetFixture _testAssetFixture; | ||
|
||
public MaxFailedTestsExtensionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) | ||
: base(testExecutionContext) => _testAssetFixture = testAssetFixture; | ||
|
||
[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] | ||
public async Task SimpleMaxFailedTestsScenario(string tfm) | ||
{ | ||
var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); | ||
|
||
TestHostResult testHostResult = await testHost.ExecuteAsync("--maximum-failed-tests 2"); | ||
testHostResult.AssertExitCodeIs(ExitCodes.TestExecutionStoppedForMaxFailedTests); | ||
|
||
int total = int.Parse(Regex.Match(testHostResult.StandardOutput, @"total: (\d+)").Groups[1].Value, CultureInfo.InvariantCulture); | ||
|
||
// We can't know the number of tests that will be executed exactly due to the async | ||
// nature of publish/consume on the platform side. But we expect the cancellation to | ||
// happen "fast" enough that we don't execute all tests. | ||
Assert.IsTrue(total < 12); | ||
Assert.IsTrue(total >= 5); | ||
|
||
testHostResult = await testHost.ExecuteAsync(); | ||
testHostResult.AssertExitCodeIs(ExitCodes.AtLeastOneTestFailed); | ||
|
||
total = int.Parse(Regex.Match(testHostResult.StandardOutput, @"total: (\d+)").Groups[1].Value, CultureInfo.InvariantCulture); | ||
Assert.AreEqual(12, total); | ||
} | ||
|
||
[TestFixture(TestFixtureSharingStrategy.PerTestGroup)] | ||
public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) | ||
{ | ||
private const string Sources = """ | ||
#file MaxFailedTestsExtensionTests.csproj | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks> | ||
<EnableMSTestRunner>true</EnableMSTestRunner> | ||
<OutputType>Exe</OutputType> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>preview</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" /> | ||
<PackageReference Include="MSTest" Version="$MSTestVersion$" /> | ||
</ItemGroup> | ||
</Project> | ||
#file UnitTest1.cs | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
[TestClass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void Test1() | ||
{ | ||
Assert.Fail(); | ||
} | ||
[TestMethod] | ||
public void Test2() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test3() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test4() | ||
{ | ||
Assert.Fail(); | ||
} | ||
[TestMethod] | ||
public void Test5() | ||
{ | ||
Assert.Fail(); | ||
} | ||
[TestMethod] | ||
public void Test6() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test7() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test8() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test9() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test10() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test11() | ||
{ | ||
} | ||
[TestMethod] | ||
public void Test12() | ||
{ | ||
} | ||
} | ||
"""; | ||
|
||
public string TargetAssetPath => GetAssetPath(AssetName); | ||
|
||
public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate() | ||
{ | ||
yield return (AssetName, AssetName, | ||
Sources | ||
.PatchTargetFrameworks(TargetFrameworks.All) | ||
.PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) | ||
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); | ||
} | ||
} | ||
} |