Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestRunRequestEventsRegistrar null in run specific tests #2051

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -137,6 +137,11 @@ internal class RunSpecificTestsArgumentExecutor : IArgumentExecutor
/// </summary>
private ITestDiscoveryEventsRegistrar discoveryEventsRegistrar;

/// <summary>
/// Registers and Unregisters for test run events before and after test run
/// </summary>
private ITestRunEventsRegistrar testRunEventsRegistrar;

#endregion

#region Constructor
Expand All @@ -159,6 +164,7 @@ internal class RunSpecificTestsArgumentExecutor : IArgumentExecutor
this.runSettingsManager = runSettingsProvider;
this.output = output;
this.discoveryEventsRegistrar = new DiscoveryEventsRegistrar(this.discoveryRequest_OnDiscoveredTests);
this.testRunEventsRegistrar = new TestRunRequestEventsRegistrar(this.output, this.commandLineOptions);
}

#endregion
Expand Down Expand Up @@ -259,7 +265,7 @@ private void ExecuteSelectedTests()

EqtTrace.Verbose("RunSpecificTestsArgumentProcessor:Execute: Test run is queued.");
var runRequestPayload = new TestRunRequestPayload() { TestCases = this.selectedTestCases.ToList(), RunSettings = this.effectiveRunSettings, KeepAlive = keepAlive, TestPlatformOptions = new TestPlatformOptions() { TestCaseFilter = this.commandLineOptions.TestCaseFilterValue }};
this.testRequestManager.RunTests(runRequestPayload, null, null, Constants.DefaultProtocolConfig);
this.testRequestManager.RunTests(runRequestPayload, null, this.testRunEventsRegistrar, Constants.DefaultProtocolConfig);
}
else
{
Expand Down Expand Up @@ -335,5 +341,53 @@ public void UnregisterDiscoveryEvents(IDiscoveryRequest discoveryRequest)
discoveryRequest.OnDiscoveredTests -= this.discoveredTestsHandler;
}
}

private class TestRunRequestEventsRegistrar : ITestRunEventsRegistrar
{
private IOutput output;
private CommandLineOptions commandLineOptions;

public TestRunRequestEventsRegistrar(IOutput output, CommandLineOptions commandLineOptions)
{
this.output = output;
this.commandLineOptions = commandLineOptions;
}

public void LogWarning(string message)
{
ConsoleLogger.RaiseTestRunWarning(message);
}

public void RegisterTestRunEvents(ITestRunRequest testRunRequest)
{
testRunRequest.OnRunCompletion += TestRunRequest_OnRunCompletion;
}

public void UnregisterTestRunEvents(ITestRunRequest testRunRequest)
{
testRunRequest.OnRunCompletion -= TestRunRequest_OnRunCompletion;
}

/// <summary>
/// Handles the TestRunRequest complete event
/// </summary>
/// <param name="sender"></param>
/// <param name="e">RunCompletion args</param>
private void TestRunRequest_OnRunCompletion(object sender, TestRunCompleteEventArgs e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test this please

{
// If run is not aborted/cancelled then check the count of executed tests.
// we need to check if there are any tests executed - to try show some help info to user to check for installed vsix extensions
if (!e.IsAborted && !e.IsCanceled)
{
var testsFoundInAnySource = (e.TestRunStatistics == null) ? false : (e.TestRunStatistics.ExecutedTests > 0);

// Indicate the user to use testadapterpath command if there are no tests found
if (!testsFoundInAnySource && string.IsNullOrEmpty(CommandLineOptions.Instance.TestAdapterPath) && this.commandLineOptions.TestCaseFilterValue == null)
{
this.output.Warning(false, CommandLineResources.SuggestTestAdapterPathIfNoTestsIsFound);
}
}
}
}
}
}
Expand Up @@ -435,7 +435,7 @@ private void CheckSourcesForCompatibility(Framework chosenFramework, Architectur
if (!string.IsNullOrEmpty(incompatibleSettingWarning))
{
EqtTrace.Warning(incompatibleSettingWarning);
registrar.LogWarning(incompatibleSettingWarning);
registrar?.LogWarning(incompatibleSettingWarning);
}

// Log compatible sources
Expand Down
24 changes: 24 additions & 0 deletions test/Microsoft.TestPlatform.AcceptanceTests/FrameworkTests.cs
Expand Up @@ -50,5 +50,29 @@ public void OnWrongFrameworkPassedTestRunShouldNotRun(RunnerInfo runnerInfo)
this.StdErrorContains("Test Run Aborted.");
}
}

[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
public void RunSpecificTestsShouldWorkWithFrameworkInCompatibleWarning(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var arguments = PrepareArguments(GetSampleTestAssembly(), string.Empty, string.Empty, this.FrameworkArgValue);
arguments = string.Concat(arguments, " ", "/tests:PassingTest");
arguments = string.Concat(arguments, " ", "/Framework:Framework40");

this.InvokeVsTest(arguments);

if (runnerInfo.TargetFramework.Contains("netcore"))
{
this.StdOutputContains("No test is available");
}
else
{
this.StdOutputContains("Following DLL(s) do not match framework/platform settings. ");
this.ValidateSummaryStatus(1, 0, 0);
}
}
}
}