diff --git a/src/dotnet-trx-merge/Services/TrxFetcher.cs b/src/dotnet-trx-merge/Services/TrxFetcher.cs
index 02ee28d..6c324b2 100644
--- a/src/dotnet-trx-merge/Services/TrxFetcher.cs
+++ b/src/dotnet-trx-merge/Services/TrxFetcher.cs
@@ -27,12 +27,22 @@ private XDocument FetchOnlyLatest(string[] filesToMerge)
TestTimes testTimes = new TestTimes();
foreach (var trxFile in filesToMerge)
{
+ _log.Debug($"Processing file {trxFile}");
var trxDocument = XDocument.Load(trxFile);
XElement? rootElement = trxDocument.Root;
if (rootElement == null)
throw new Exception($"Could not find root element in file {trxFile}");
ns = rootElement.GetDefaultNamespace();
- runUser ??= rootElement.Attribute("runUser")!.Value;
+ var runUserElement = rootElement.Attribute("runUser");
+ if (runUserElement != null)
+ {
+ runUser ??= runUserElement.Value;
+ } else
+ {
+ _log.Warning($"Could not find runUser attribute in file {trxFile}. Defaulting to UnknownRunUser");
+ runUser = "UnknownRunUser";
+ }
+
testTimes.AddTestTimes(rootElement.Descendants(ns+"Times").FirstOrDefault());
var results = trxDocument.Descendants(ns + "UnitTestResult");
var definitions = trxDocument.Descendants(ns + "UnitTest");
diff --git a/test/dotnet-trx-merge.IntegrationTests/dotnet-trx-merge.IntegrationTests.csproj b/test/dotnet-trx-merge.IntegrationTests/dotnet-trx-merge.IntegrationTests.csproj
index fce5e20..e1a8173 100644
--- a/test/dotnet-trx-merge.IntegrationTests/dotnet-trx-merge.IntegrationTests.csproj
+++ b/test/dotnet-trx-merge.IntegrationTests/dotnet-trx-merge.IntegrationTests.csproj
@@ -18,7 +18,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/test/dotnet-trx-merge.UnitTests/Commands/MergeCommandTests.cs b/test/dotnet-trx-merge.UnitTests/Commands/MergeCommandTests.cs
index d939f40..46a92d7 100644
--- a/test/dotnet-trx-merge.UnitTests/Commands/MergeCommandTests.cs
+++ b/test/dotnet-trx-merge.UnitTests/Commands/MergeCommandTests.cs
@@ -50,7 +50,7 @@ public void Run_TestsOnce_WithDirectory_NoFailures()
command.Run();
// Assert
- trxFetcher.Received(1).AddLatestTests(Arg.Is(files => files.Count() == 12));
+ trxFetcher.Received(1).AddLatestTests(Arg.Is(files => files.Count() == 13));
}
[Fact]
diff --git a/test/dotnet-trx-merge.UnitTests/Fixtures/Merge/TrxWithNoRunUser.trx b/test/dotnet-trx-merge.UnitTests/Fixtures/Merge/TrxWithNoRunUser.trx
new file mode 100644
index 0000000..8ba982f
--- /dev/null
+++ b/test/dotnet-trx-merge.UnitTests/Fixtures/Merge/TrxWithNoRunUser.trx
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/dotnet-trx-merge.UnitTests/Services/TrxFetcherTests.cs b/test/dotnet-trx-merge.UnitTests/Services/TrxFetcherTests.cs
index e676d84..6e47a63 100644
--- a/test/dotnet-trx-merge.UnitTests/Services/TrxFetcherTests.cs
+++ b/test/dotnet-trx-merge.UnitTests/Services/TrxFetcherTests.cs
@@ -9,6 +9,7 @@ namespace dotnet_test_rerun.UnitTests.Services;
public class TrxFetcherTests
{
+ private const string TrxWithNoRunUser = "../../../Fixtures/Merge/TrxWithNoRunUser.trx";
private const string TrxAllPass = "../../../Fixtures/Merge/TrxAllPass.trx";
private const string TrxWithFailures = "../../../Fixtures/Merge/TrxWithFailures.trx";
private const string TrxWithErrors = "../../../Fixtures/Merge/TrxWithErrors.trx";
@@ -693,6 +694,46 @@ public void AddLatestTests_WhenNamespaces_OutputShouldHaveNamespace()
ValidateOutcome(mergedDocument, 2, 2, 0, "Completed");
}
+ [Fact]
+ public void AddLatestTests_WithOneFileWithNoRunUser_AllPass()
+ {
+ // Arrange
+ var logger = new Logger();
+ var trxFetcher = new TrxFetcher(logger);
+
+ // Act
+ var mergedDocument = trxFetcher.AddLatestTests(new[] { TrxWithNoRunUser });
+
+ // Assert
+ var results = mergedDocument.Descendants("UnitTestResult");
+ results.Should().HaveCount(1);
+ ValidateTestResult(results.ElementAt(0),
+ "e68ff2c7-8309-483b-a1fd-414967943cf0",
+ "86e2b6e4-df7a-e4fa-006e-c056c908e219",
+ "SecondSimpleNumberCompare",
+ "Passed");
+
+ var definitions = mergedDocument.Descendants("UnitTest");
+ definitions.Should().HaveCount(1);
+ ValidateTestDefinition(definitions.ElementAt(0),
+ "e68ff2c7-8309-483b-a1fd-414967943cf0",
+ "86e2b6e4-df7a-e4fa-006e-c056c908e219",
+ "SecondSimpleNumberCompare");
+
+ var entries = mergedDocument.Descendants("TestEntry");
+ entries.Should().HaveCount(1);
+ ValidateTestEntry(entries.ElementAt(0),
+ "e68ff2c7-8309-483b-a1fd-414967943cf0",
+ "86e2b6e4-df7a-e4fa-006e-c056c908e219");
+
+ ValidateOutcome(mergedDocument, 1, 1, 0, "Completed");
+ ValidateTimes(mergedDocument.Descendants("Times").First(),
+ "2023-08-29T18:35:26.3589967+01:00",
+ "2023-08-29T18:35:26.3589971+01:00",
+ "2023-08-29T18:35:25.5259659+01:00",
+ "2023-08-29T18:35:26.3652254+01:00");
+ }
+
private void ValidateTimes(XElement times, string creation, string queued, string start, string finish)
{
times.Attribute("creation")!.Value.Should().Be(creation);
diff --git a/test/dotnet-trx-merge.UnitTests/dotnet-trx-merge.UnitTests.csproj b/test/dotnet-trx-merge.UnitTests/dotnet-trx-merge.UnitTests.csproj
index 7d5b25d..30703d2 100644
--- a/test/dotnet-trx-merge.UnitTests/dotnet-trx-merge.UnitTests.csproj
+++ b/test/dotnet-trx-merge.UnitTests/dotnet-trx-merge.UnitTests.csproj
@@ -18,7 +18,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all