diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/DataProcessor.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/DataProcessor.cs index c5a4665c09a25..4160b862d8729 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/DataProcessor.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/DataProcessor.cs @@ -143,13 +143,14 @@ public static RawTestResult GetRawResultObject(TestResult? testResultSource) { if (testResultSource == null) return new RawTestResult(); - List errors = new();//[testResultSource.ErrorMessage]; + List errors = new(); if (testResultSource.ErrorMessage != null) errors.Add(new MPTError() { message = testResultSource.ErrorMessage }); + if (testResultSource.ErrorStackTrace != null) + errors.Add(new MPTError() { message = testResultSource.ErrorStackTrace }); var rawTestResult = new RawTestResult { - errors = JsonSerializer.Serialize(errors), - stdErr = testResultSource?.ErrorStackTrace ?? string.Empty + errors = JsonSerializer.Serialize(errors) }; return rawTestResult; } diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/DataProcessorTests.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/DataProcessorTests.cs index 42b423e35767d..ebf5745770256 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/DataProcessorTests.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/DataProcessorTests.cs @@ -160,6 +160,22 @@ public void GetRawResultObject_WithNullTestResult_ReturnsRawTestResultWithEmptyE Assert.AreEqual("[]", result.stdErr); } + [Test] + public void GetRawResultObject_WithNullErrorStackTrace_ReturnsRawTestResultWithEmptyErrorsAndStdErr() + { + var testResult = new TestResult(new TestCase("Test", new System.Uri("file:///test.cs"), "TestNamespace.TestClass")) + { + ErrorMessage = null, + ErrorStackTrace = null + }; + + RawTestResult result = DataProcessor.GetRawResultObject(testResult); + + Assert.IsNotNull(result); + Assert.AreEqual("[]", result.errors); + Assert.AreEqual("[]", result.stdErr); + } + [Test] public void GetRawResultObject_WithNonNullTestResult_ReturnsRawTestResultWithErrorsAndStdErr() { @@ -172,8 +188,7 @@ public void GetRawResultObject_WithNonNullTestResult_ReturnsRawTestResultWithErr RawTestResult result = DataProcessor.GetRawResultObject(testResult); Assert.IsNotNull(result); - Assert.AreEqual("[{\"message\":\"An error occurred\"}]", result.errors); - Assert.AreEqual("Error stack trace", result.stdErr); + Assert.AreEqual("[{\"message\":\"An error occurred\"},{\"message\":\"Error stack trace\"}]", result.errors); } } }