Skip to content

Commit

Permalink
Remove static test run
Browse files Browse the repository at this point in the history
  • Loading branch information
Jandini committed Oct 15, 2023
1 parent f96b650 commit 870a87b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/KiBoards.Xunit/Models/KiBoardsTestCaseRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class KiBoardsTestCaseRun
{
public string Id { get; internal set; }
public TestRun TestRun { get; set; }
public KiBoardsTestRun TestRun { get; set; }
public KiBoardsTestCase TestCase { get; set; }
public KiBoardsTestCaseRunSkipped Skipped { get; set; }
public KiBoardsTestCaseRunFailed Failed { get; set; }
Expand Down
19 changes: 19 additions & 0 deletions src/KiBoards.Xunit/Models/KiBoardsTestRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Nest;
using System.Collections;

namespace KiBoards.Models
{
public class KiBoardsTestRun
{
public string Id { get; internal set; }
public string Name { get; internal set; }
public string Hash { get; internal set; }
public DateTime StartTime { get; internal set; }
public string MachineName { get; internal set; }
public string UserName { get; internal set; }
public Dictionary<string, string> Variables { get; internal set; }

[Object]
internal KiBoardsTestRunSummary Summary { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace KiBoards
namespace KiBoards.Models
{
class TestRunSummary
class KiBoardsTestRunSummary
{
/// <summary>
/// The total number of tests run.
Expand Down
51 changes: 15 additions & 36 deletions src/KiBoards.Xunit/TestFramework.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using KiBoards.Services;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace KiBoards
{
public class TestFramework : XunitTestFramework, IDisposable
{
public static readonly TestRun TestRun = new();
{
readonly KiBoardsTestRunner _testRunner;

readonly KiBoardsTestRunner _testRunner;

public TestFramework(IMessageSink messageSink)
: base(messageSink)
{
{
_testRunner = new KiBoardsTestRunner(messageSink);
}


protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
{
return new TestFrameworkExecutor(assemblyName, SourceInformationProvider, DiagnosticMessageSink, _testRunner);
Expand All @@ -34,30 +31,23 @@ public TestFrameworkExecutor(AssemblyName assemblyName, ISourceInformationProvid
: base(assemblyName, sourceInformationProvider, diagnosticMessageSink)
{
_testRunner = testRunner;
_diagnosticMessageSink = diagnosticMessageSink;
_diagnosticMessageSink = diagnosticMessageSink;
}



protected override async void RunTestCases(IEnumerable<IXunitTestCase> testCases, IMessageSink executionMessageSink, ITestFrameworkExecutionOptions executionOptions)
{
try
{
using var assemblyRunner = new TestAssemblyRunner(TestAssembly, testCases, DiagnosticMessageSink, executionMessageSink, executionOptions, _testRunner);
var summary = await assemblyRunner.RunAsync();

TestRun.Summary = new TestRunSummary()
{
Total = summary.Total,
Failed = summary.Failed,
Skipped = summary.Skipped,
Time = summary.Time,
};

await _testRunner.IndexTestRunAsync(TestRun);
var summary = await assemblyRunner.RunAsync();
await _testRunner.IndexTestRunAsync(summary);

}
catch (Exception ex)
{
_diagnosticMessageSink.OnMessage(new DiagnosticMessage(ex.Message, ex.StackTrace));
_diagnosticMessageSink.WriteException(ex);
}
}
}
Expand All @@ -80,11 +70,7 @@ protected override async Task<RunSummary> RunTestCollectionAsync(IMessageBus mes
return await collectionRunner.RunAsync();
}

protected override string GetTestFrameworkDisplayName()
{
var version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
return $"KiBoards {version}";
}
protected override string GetTestFrameworkDisplayName() => $"KiBoards {_testRunner.Version}";
}


Expand All @@ -110,21 +96,14 @@ private class TestClassRunner : XunitTestClassRunner

public TestClassRunner(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable<IXunitTestCase> testCases, IMessageSink diagnosticMessageSink, IMessageBus messageBus, ITestCaseOrderer testCaseOrderer, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource, IDictionary<Type, object> collectionFixtureMappings, KiBoardsTestRunner testRunner)
: base(testClass, @class, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource, collectionFixtureMappings)
{
TestRun.Name = string.Join(",", testCases.Select(a => Path.GetFileNameWithoutExtension(a.TestMethod.TestClass.Class.Assembly.AssemblyPath)).Distinct());
TestRun.Hash = string.Join(",", testCases.OrderBy(a => a.UniqueID).Select(a => a.UniqueID)).ComputeMD5();

{
_testRunner = testRunner;
testRunner.AddTestCases(testCases);
}

protected override Task<RunSummary> RunTestMethodAsync(ITestMethod testMethod, IReflectionMethodInfo method, IEnumerable<IXunitTestCase> testCases, object[] constructorArguments)
=> new TestMethodRunner(testMethod, Class, method, testCases, DiagnosticMessageSink, new TestResultBus(MessageBus), new ExceptionAggregator(Aggregator), CancellationTokenSource, constructorArguments, _testRunner)
.RunAsync();

protected override async Task<RunSummary> RunTestMethodsAsync()
{
return await base.RunTestMethodsAsync();
}
.RunAsync();
}


Expand Down Expand Up @@ -177,7 +156,7 @@ protected override async Task<RunSummary> RunTestCaseAsync(IXunitTestCase testCa
}
catch (Exception ex)
{
_diagnosticMessageSink.OnMessage(new DiagnosticMessage(ex.Message, ex.StackTrace));
_diagnosticMessageSink.WriteException(ex);
}

return result;
Expand Down
25 changes: 0 additions & 25 deletions src/KiBoards.Xunit/TestRun.cs

This file was deleted.

0 comments on commit 870a87b

Please sign in to comment.