From b2979173c5fd04027fd65b68bf6872fc8f05af18 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 10 Nov 2020 14:54:36 +1100 Subject: [PATCH] fail the junit test if there were any failed test cases Signed-off-by: Lachlan Roberts --- .../core/autobahn/AutobahnTests.java | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java index a6f5a083dfc..18c96734715 100644 --- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java +++ b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java @@ -109,6 +109,7 @@ public class AutobahnTests List results = parseResults(Paths.get("target/reports/clients/index.json")); String className = getClass().getName(); writeJUnitXmlReport(results, "autobahn-client", className + ".client"); + throwIfFailed(results); } @Test @@ -139,6 +140,20 @@ public class AutobahnTests List results = parseResults(Paths.get("target/reports/servers/index.json")); String className = getClass().getName(); writeJUnitXmlReport(results, "autobahn-server", className + ".server"); + throwIfFailed(results); + } + + private void throwIfFailed(List results) throws Exception + { + StringBuilder message = new StringBuilder(); + for (AutobahnCaseResult result : results) + { + if (result.failed()) + message.append(result.caseName).append(", "); + } + + if (message.length() > 0) + throw new Exception("Failed Test Cases: " + message); } private static class FileSignalWaitStrategy extends StartupCheckStrategy @@ -232,21 +247,11 @@ public class AutobahnTests suiteDuration += duration; testcase.setAttribute("time", Double.toString(duration / 1000.0)); - // failOnNonStrict option ? - switch (r.behavior()) + if (r.failed()) { - case OK: - case INFORMATIONAL: - case UNIMPLEMENTED: - break; - - case NON_STRICT: - default: - addFailure(testcase,r); - failures++; - break; + addFailure(testcase,r); + failures++; } - root.addChild(testcase); } root.setAttribute("failures", Integer.toString(failures)); @@ -390,6 +395,21 @@ public class AutobahnTests return behavior; } + public boolean failed() + { + switch (behavior) + { + case OK: + case INFORMATIONAL: + case UNIMPLEMENTED: + return false; + + case NON_STRICT: + default: + return true; + } + } + public Behavior behaviorClose() { return behaviorClose;