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

Add framework version and test run status #18

Merged
merged 1 commit into from
Oct 15, 2023
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
13 changes: 5 additions & 8 deletions src/KiBoards.Xunit/Models/KiBoardsTestRun.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using Nest;
using System.Collections;

namespace KiBoards.Models
namespace KiBoards.Models
{
public class KiBoardsTestRun
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 string Status { get; internal set; }
public Dictionary<string, string> Variables { get; internal set; }

[Object]
internal KiBoardsTestRunSummary Summary { get; set; }
public string FrameworkVersion { get; internal set; }
public KiBoardsTestRunSummary Summary { get; set; }
}
}
11 changes: 8 additions & 3 deletions src/KiBoards.Xunit/Services/KiBoardsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ public KiBoardsTestRunner(IMessageSink messageSink)
{
try
{
Version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;

_testRun = new KiBoardsTestRun()
{
Id = Guid.NewGuid().ToString(),
StartTime = DateTime.UtcNow,
MachineName = Environment.MachineName,
UserName = Environment.UserName,
FrameworkVersion = Version,
Variables = new Dictionary<string, string>()
};

Expand All @@ -44,6 +47,7 @@ public KiBoardsTestRunner(IMessageSink messageSink)
var uriString = Environment.GetEnvironmentVariable("KIB_ELASTICSEARCH_HOST") ?? "http://localhost:9200";
var connectionSettings = new ConnectionSettings(new Uri(uriString));


var elasticClient = new ElasticClient(connectionSettings
.DefaultMappingFor<KiBoardsTestRun>(m => m
.IndexName($"kiboards-testruns-{DateTime.UtcNow:yyyy-MM}")
Expand All @@ -56,8 +60,7 @@ public KiBoardsTestRunner(IMessageSink messageSink)
.MaximumRetries(3));

_elasticService = new KiBoardsElasticClient(elasticClient, messageSink);

Version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;

messageSink.WriteMessage($"KiBoards.Xunit {Version} logging to {uriString}");
}
catch (Exception ex)
Expand Down Expand Up @@ -102,6 +105,8 @@ public async Task IndexTestRunAsync(RunSummary summary)
Time = summary.Time,
};

_testRun.Status = summary.Failed > 0 ? "Failed" : summary.Skipped == summary.Total ? "Skipped" : "Passed";

await _elasticService.IndexDocumentAsync(_testRun);
}

Expand Down Expand Up @@ -147,7 +152,7 @@ await _elasticService.IndexDocumentAsync(new KiBoardsTestCaseRun()
});
}

internal void AddTestCases(IEnumerable<IXunitTestCase> testCases)
internal void UpdateRun(IEnumerable<IXunitTestCase> testCases)
{
_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();
Expand Down
2 changes: 1 addition & 1 deletion src/KiBoards.Xunit/TestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public TestClassRunner(ITestClass testClass, IReflectionTypeInfo @class, IEnumer
: base(testClass, @class, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource, collectionFixtureMappings)
{
_testRunner = testRunner;
testRunner.AddTestCases(testCases);
testRunner.UpdateRun(testCases);
}

protected override Task<RunSummary> RunTestMethodAsync(ITestMethod testMethod, IReflectionMethodInfo method, IEnumerable<IXunitTestCase> testCases, object[] constructorArguments)
Expand Down
Loading