From 192f4b2ac3ba5fba2fe094e443dc9a7c01f2d264 Mon Sep 17 00:00:00 2001 From: Puneet Agarwal Date: Thu, 7 Nov 2024 15:21:35 +0530 Subject: [PATCH 1/2] Adding stacktrace into error list --- .../src/Processor/DataProcessor.cs | 7 ++++--- .../tests/Processor/DataProcessorTests.cs | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) 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..f96a0725787d7 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/DataProcessorTests.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Processor/DataProcessorTests.cs @@ -172,8 +172,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); } } } From 231f7b656998bde63cb9812f636fa13d7857d016 Mon Sep 17 00:00:00 2001 From: Puneet Agarwal Date: Fri, 8 Nov 2024 14:35:27 +0530 Subject: [PATCH 2/2] add test for null value --- .../tests/Processor/DataProcessorTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 f96a0725787d7..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() {