Skip to content

Commit

Permalink
add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Rossignoli committed Nov 28, 2022
1 parent 2900acd commit f76afde
Showing 1 changed file with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
Expand All @@ -21,11 +22,18 @@ public class SerializeTestRunTests : AcceptanceTestBase
private RunEventHandler? _runEventHandler;
private DiscoveryEventHandler? _discoveryEventHandler;
private DiscoveryEventHandler2? _discoveryEventHandler2;
private readonly string _runsettings = @"
<RunSettings>
<RunConfiguration>
<SerializeTestRun>true</SerializeTestRun>
</RunConfiguration>
</RunSettings>
";

[MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_runEventHandler), nameof(_discoveryEventHandler), nameof(_discoveryEventHandler2))]
private void Setup()
private void Setup(Dictionary<string, string?>? environmentVariables = null)
{
_vstestConsoleWrapper = GetVsTestConsoleWrapper();
_vstestConsoleWrapper = GetVsTestConsoleWrapper(environmentVariables);
_discoveryEventHandler = new DiscoveryEventHandler();
_discoveryEventHandler2 = new DiscoveryEventHandler2();
_runEventHandler = new RunEventHandler();
Expand All @@ -46,18 +54,10 @@ public void DiscoverTestsAndRunTestsSequentially(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);
Setup();

string runsettings = @"
<RunSettings>
<RunConfiguration>
<SerializeTestRun>true</SerializeTestRun>
</RunConfiguration>
</RunSettings>
";

// Act
var testDll = GetAssetFullPath("SerializeTestRunTestProject.dll");
_vstestConsoleWrapper.DiscoverTests(new string[] { testDll }, GetDefaultRunSettings(), _discoveryEventHandler);
_vstestConsoleWrapper.RunTests(_discoveryEventHandler.DiscoveredTestCases, runsettings, _runEventHandler);
_vstestConsoleWrapper.RunTests(_discoveryEventHandler.DiscoveredTestCases, _runsettings, _runEventHandler);
_runEventHandler.EnsureSuccess();

// Assert
Expand All @@ -66,6 +66,28 @@ public void DiscoverTestsAndRunTestsSequentially(RunnerInfo runnerInfo)
Assert.IsFalse(failedTests > 0, $"Number of failed tests {failedTests}");
}

[TestMethod]
[NetCoreTargetFrameworkDataSource]
[NetFullTargetFrameworkDataSource]
public void DiscoverTestsAndRunTestsSequentially_DisabledByFeatureFlag(RunnerInfo runnerInfo)
{
// Arrange
SetTestEnvironment(_testEnvironment, runnerInfo);
Dictionary<string, string?>? environmentVariables = new() { { "VSTEST_DISABLE_SERIALIZETESTRUN_DECORATOR", "1" } };
Setup(environmentVariables);

// Act
var testDll = GetAssetFullPath("SerializeTestRunTestProject.dll");
_vstestConsoleWrapper.DiscoverTests(new string[] { testDll }, GetDefaultRunSettings(), _discoveryEventHandler);
_vstestConsoleWrapper.RunTests(_discoveryEventHandler.DiscoveredTestCases, _runsettings, _runEventHandler);
_runEventHandler.EnsureSuccess();

// Assert
Assert.AreEqual(10, _discoveryEventHandler.DiscoveredTestCases.Count);
int failedTests = _runEventHandler.TestResults.Count(x => x.Outcome == TestOutcome.Failed);
Assert.IsTrue(failedTests > 0, $"Number of failed tests {failedTests}");
}

[TestMethod]
[NetCoreTargetFrameworkDataSource]
[NetFullTargetFrameworkDataSource]
Expand All @@ -75,17 +97,9 @@ public void DiscoverTestsAndRunTestsSequentially_IsNotSupportedForSources(Runner
SetTestEnvironment(_testEnvironment, runnerInfo);
Setup();

string runsettings = @"
<RunSettings>
<RunConfiguration>
<SerializeTestRun>true</SerializeTestRun>
</RunConfiguration>
</RunSettings>
";

// Act
var testDll = GetAssetFullPath("SerializeTestRunTestProject.dll");
_vstestConsoleWrapper.RunTests(new string[] { testDll }, runsettings, _runEventHandler);
_vstestConsoleWrapper.RunTests(new string[] { testDll }, _runsettings, _runEventHandler);
_ = Assert.ThrowsException<InvalidOperationException>(_runEventHandler.EnsureSuccess);

StringBuilder builder = new();
Expand Down

0 comments on commit f76afde

Please sign in to comment.