Skip to content

Commit

Permalink
save Throwable as Java object for each failure (#151)
Browse files Browse the repository at this point in the history
* Save throwable as object

Wrap Throwable in Optional

* Make Failure serializable

* Add easymock as dependency

* Revert "Add easymock as dependency"

This reverts commit 7690aa1.

* Use SerializableThrowable to save to file
  • Loading branch information
leonardhusmann authored Nov 7, 2024
1 parent e8176c9 commit 323c709
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/eu/stamp_project/testrunner/runner/Failure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}
}

}

0 comments on commit 323c709

Please sign in to comment.