Skip to content

Commit

Permalink
feat: exclude assemblies without executed tests from the summary
Browse files Browse the repository at this point in the history
  • Loading branch information
vchirikov committed Oct 25, 2022
1 parent ab8ccd3 commit c1056d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/dotnet/Logger/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,29 +256,33 @@ async Task OnTestRunCompleteInternalAsync(TestRunCompleteEventArgs results)
try
{
await Task.WhenAll(_testResults.Values.ToArray()).ConfigureAwait(false);
if (!results.TestRunStatistics.Stats.TryGetValue(TestOutcome.Passed, out var passed))
passed = 0;
if (!results.TestRunStatistics.Stats.TryGetValue(TestOutcome.Failed, out var failed))
failed = 0;
if (!results.TestRunStatistics.Stats.TryGetValue(TestOutcome.Skipped, out var skipped))
skipped = 0;
// write summary only if filter will get some tests for assembly
if (results.TestRunStatistics.ExecutedTests > 0)
{
if (!results.TestRunStatistics.Stats.TryGetValue(TestOutcome.Passed, out var passed))
passed = 0;
if (!results.TestRunStatistics.Stats.TryGetValue(TestOutcome.Failed, out var failed))
failed = 0;
if (!results.TestRunStatistics.Stats.TryGetValue(TestOutcome.Skipped, out var skipped))
skipped = 0;

var summary = _summaryGenerator.Generate(
name: _params.name,
suite: _testRunName,
framework: _testRunFramework,
passed,
failed,
skipped,
total: results.TestRunStatistics.ExecutedTests,
elapsed: results.ElapsedTimeInRunningTests,
testResults: _testResults.Keys
);
var summary = _summaryGenerator.Generate(
name: _params.name,
suite: _testRunName,
framework: _testRunFramework,
passed,
failed,
skipped,
total: results.TestRunStatistics.ExecutedTests,
elapsed: results.ElapsedTimeInRunningTests,
testResults: _testResults.Keys
);

// we might have several msbuild processes (per testRun),
// so we can't just print summary into gh action output value (bc we will override the value)
// thus we must use a file to store results and work with contention between msbuilds
await _summaryWriter.WriteAsync(summary).ConfigureAwait(false);
// we might have several msbuild processes (per testRun),
// so we can't just print summary into gh action output value (bc we will override the value)
// thus we must use a file to store results and work with contention between msbuilds
await _summaryWriter.WriteAsync(summary).ConfigureAwait(false);
}
}
finally
{
Expand Down
7 changes: 7 additions & 0 deletions src/dotnet/Logger/TestRunSummaryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ internal class TestRunSummaryWriter

public async Task WriteAsync(string summary)
{
try
{
var directory = Path.GetDirectoryName(_outputFilePath);
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
}
catch { }
var bytes = Encoding.UTF8.GetBytes(summary);
await FileOperationWithRetryAsync(async () => {
var file = new FileStream(
Expand Down

0 comments on commit c1056d5

Please sign in to comment.