Skip to content

Commit

Permalink
Add number of passed tests to test run summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Jandini committed Oct 14, 2023
1 parent ab29252 commit f6e12b3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/KiBoards.Xunit/Services/KiBoardsElasticClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using KiBoards.Models;
using Nest;
using Nest;
using Xunit.Abstractions;
using Xunit.Sdk;

Expand Down
5 changes: 3 additions & 2 deletions src/KiBoards.Xunit/Services/KiBoardsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public KiBoardsTestRunner(IMessageSink messageSink)
var connectionSettings = new ConnectionSettings(new Uri(uriString));

var elasticClient = new ElasticClient(connectionSettings
.DefaultMappingFor<TestRun>(m => m
.DefaultMappingFor<TestRun>(m => m
.IndexName($"kiboards-testruns-{DateTime.UtcNow:yyyy-MM}")
.IdProperty(p => p.Id))
.DefaultMappingFor<KiBoardsTestCaseRun>(m => m
.DefaultMappingFor<KiBoardsTestCaseRun>(m => m
.IndexName($"kiboards-testcases-{DateTime.UtcNow:yyyy-MM}"))

.MaxRetryTimeout(TimeSpan.FromMinutes(5))
.EnableApiVersioningHeader()
.MaximumRetries(3));
Expand Down
15 changes: 11 additions & 4 deletions src/KiBoards.Xunit/TestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ public TestFrameworkExecutor(AssemblyName assemblyName, ISourceInformationProvid
{
_testRunner = testRunner;
_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);
TestRun.Summary = await assemblyRunner.RunAsync();
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);

}
Expand Down
7 changes: 5 additions & 2 deletions src/KiBoards.Xunit/TestRun.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Xunit.Sdk;
using Nest;

namespace KiBoards
{
Expand All @@ -9,7 +9,10 @@ public class TestRun
public string MachineName { get; internal set; }
public string UserName { get; internal set; }
public object Context { get; internal set; }
public RunSummary Summary { get; internal set; }


[Object]
internal TestRunSummary Summary { get; set; }

public TestRun()
{
Expand Down
30 changes: 30 additions & 0 deletions src/KiBoards.Xunit/TestRunSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace KiBoards
{
class TestRunSummary
{
/// <summary>
/// The total number of tests run.
/// </summary>
public int Total { get; internal set; }

/// <summary>
/// The number of failed tests.
/// </summary>
public int Failed { get; internal set; }

/// <summary>
/// The number of skipped tests.
/// </summary>
public int Skipped { get; internal set; }

/// <summary>
/// Compute number of passed tests
/// </summary>
public int Passed { get => Total - Failed - Skipped; }

/// <summary>
/// The total time taken to run the tests, in seconds.
/// </summary>
public decimal Time { get; internal set; }
}
}

0 comments on commit f6e12b3

Please sign in to comment.