Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save Throwable as Java object for each failure #151

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}

}
Loading