From 323c709b4a4988e385d8b236dfe99cb0f3bdbfdd Mon Sep 17 00:00:00 2001 From: Leonard Husmann <41958952+leonardhusmann@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:05:34 +0100 Subject: [PATCH] save Throwable as Java object for each failure (#151) * Save throwable as object Wrap Throwable in Optional * Make Failure serializable * Add easymock as dependency * Revert "Add easymock as dependency" This reverts commit 7690aa1543e21b6e11e0ff5379a32c567d3afe6d. * Use SerializableThrowable to save to file --- .../testrunner/runner/Failure.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/eu/stamp_project/testrunner/runner/Failure.java b/src/main/java/eu/stamp_project/testrunner/runner/Failure.java index c38b3d7c..a2510754 100644 --- a/src/main/java/eu/stamp_project/testrunner/runner/Failure.java +++ b/src/main/java/eu/stamp_project/testrunner/runner/Failure.java @@ -13,11 +13,14 @@ */ public class Failure implements Serializable { + private final static long serialVersionUID = 4319480863941757524L; + public final String testCaseName; public final String testClassName; public final String fullQualifiedNameOfException; public final String messageOfFailure; public final String stackTrace; + public SerializableThrowable throwable; // Throwable is not present if Failure is read from surefire report public Failure(String testCaseName, String testClassName, Throwable exception) { this.testCaseName = testCaseName; @@ -28,6 +31,7 @@ public Failure(String testCaseName, String testClassName, Throwable exception) { PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); this.stackTrace = sw.toString(); // stack trace as a string + this.throwable = new SerializableThrowable(exception); } public Failure(String testCaseName, String testClassName, String fullQualifiedNameOfException, String messageOfFailure, String stackTrace) { @@ -64,4 +68,21 @@ public int hashCode() { result = 31 * result + (messageOfFailure != null ? messageOfFailure.hashCode() : 0); return result; } + + + public static class SerializableThrowable implements Serializable { + + private static final long serialVersionUID = 2988580623727952827L; + + public final String className; + public final String message; + public final StackTraceElement[] stackTrace; + + public SerializableThrowable(Throwable throwable) { + this.className = throwable.getClass().getName(); + this.message = throwable.getMessage(); + this.stackTrace = throwable.getStackTrace(); + } + } + } \ No newline at end of file