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

[Runners] Add events to notify that a test run started and completed. #46

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public override async Task RunAsync()
logger.MinimumLogLevel = MinimumLogLevel.Info;
var testAssemblies = GetTestAssemblies();

var runner = await CreateRunner(logger);

// if we have ignore files, ignore those tests
await runner.Run(testAssemblies).ConfigureAwait(false);
var runner = await InternalRunAsync(logger);

TestRunner.Jargon jargon = Core.TestRunner.Jargon.NUnitV3;
switch (options.XmlVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,25 @@ public enum TestRunnerType
/// Assemblies: Provide a list of the assembly information to run.
/// assemblies can be loaded from disk or from memory, is up to the
/// implementor.
///
/// Clients that register to the class events and want to update the UI
/// are responsable to do so in the main UI thread. The application entry
/// point does not guarantee that the tests are executed in the ui thread.
///
/// </summary>
public abstract class ApplicationEntryPoint
{

/// <summary>
/// Event raised when the test run has started.
/// </summary>
public event EventHandler TestsStarted;

/// <summary>
/// Event raised when the test run has completed.
/// </summary>
public event EventHandler<TestRunResult> TestsCompleted;

protected abstract int? MaxParallelThreads { get; }
/// <summary>
/// Must be implemented and return a class that returns the information
Expand Down Expand Up @@ -73,7 +88,7 @@ public abstract class ApplicationEntryPoint
/// </summary>
public MinimumLogLevel MinimumLogLevel { get; set; } = MinimumLogLevel.Info;

protected async Task<TestRunner> CreateRunner(LogWriter logger)
protected async Task<TestRunner> InternalRunAsync (LogWriter logger)
{
logger.MinimumLogLevel = MinimumLogLevel;
TestRunner runner;
Expand Down Expand Up @@ -102,6 +117,17 @@ protected async Task<TestRunner> CreateRunner(LogWriter logger)
runner.SkipTests(skippedTests);
}
}

var testAssemblies = GetTestAssemblies();
// notify the clients we are starting
TestsStarted?.Invoke(this, new EventArgs());

await runner.Run(testAssemblies).ConfigureAwait(false);

var result = new TestRunResult(runner);
// notify the client we are done and the results, but do not expose
// the runner.
TestsCompleted?.Invoke(this, result);
return runner;
}
}
Expand Down
55 changes: 55 additions & 0 deletions src/Microsoft.DotNet.XHarness.Tests.Runners/TestRunResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.DotNet.XHarness.Tests.Runners.Core;

namespace Microsoft.DotNet.XHarness.Tests.Runners
{
public struct TestRunResult
{
/// <summary>
/// Retrieve the number of executed tests in a run.
/// </summary>
public long ExecutedTests { get; private set; }

/// <summary>
/// Retrieve the number of failed tests in a run.
/// </summary>
public long FailedTests { get; private set; }

/// <summary>
/// Retrieve the number of not executed tests due to the filters in a
/// run.
/// </summary>
public long FilteredTests { get; private set; }

/// <summary>
/// Retrieve the number of inconclusive tests in a run.
/// </summary>
public long InconclusiveTests { get; private set; }

/// <summary>
/// Retrieve the number of passed tests in a run.
/// </summary>
public long PassedTests { get; private set; }

/// <summary>
/// Retrieve the number of skipped tests in a run.
/// </summary>
public long SkippedTests { get; private set; }

/// <summary>
/// Retrieve the total number of tests in a run. This value
/// includes all skipped and filtered tests and might no be equal
/// to the value returned by ExecutedTests.
/// </summary>
public long TotalTests { get; private set; }

internal TestRunResult(TestRunner runner) {
ExecutedTests = runner.ExecutedTests;
FailedTests = runner.FailedTests;
FilteredTests = runner.FilteredTests;
InconclusiveTests = runner.InconclusiveTests;
PassedTests = runner.PassedTests;
SkippedTests = runner.SkippedTests;
TotalTests = runner.TotalTests;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ public override async Task RunAsync()
// we will write the normal console output using the LogWriter
var logger = (writer == null || options.EnableXml) ? new LogWriter(Device) : new LogWriter(Device, writer);
logger.MinimumLogLevel = MinimumLogLevel.Info;
var testAssemblies = GetTestAssemblies();
var runner = await CreateRunner(logger);

// if we have ignore files, ignore those tests
await runner.Run(testAssemblies).ConfigureAwait(false);
var runner = await InternalRunAsync(logger);

TestRunner.Jargon jargon = Core.TestRunner.Jargon.NUnitV3;
switch (options.XmlVersion)
Expand Down