Skip to content

Commit

Permalink
feat(playwrighttesting): Adding stacktrace into error list (#47014)
Browse files Browse the repository at this point in the history
* Adding stacktrace into error list

* add test for null value
  • Loading branch information
puagarwa authored Nov 8, 2024
1 parent 8c3550e commit 82b9a17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ public static RawTestResult GetRawResultObject(TestResult? testResultSource)
{
if (testResultSource == null)
return new RawTestResult();
List <MPTError> errors = new();//[testResultSource.ErrorMessage];
List <MPTError> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
}
}
}

0 comments on commit 82b9a17

Please sign in to comment.