Skip to content

Commit 10ba9aa

Browse files
committed
fix: #223 Fail in case not a success (failure or in progress) and no report on test results
Signed-off-by: Laurent Broudoux <[email protected]>
1 parent 10e1ab3 commit 10ba9aa

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/main/java/io/github/microcks/testcontainers/Assertions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static void assertSuccess(TestResult testResult) {
4141
if (!failures.isEmpty()) {
4242
throw new MultipleFailuresError("Test '" + testResult.getId() + "' has failed", failures);
4343
}
44+
throw new AssertionFailedError("Test '" + testResult.getId() + "' is not a success, but has no failure details");
4445
}
4546
}
4647

src/test/java/io/github/microcks/testcontainers/AssertionsTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,36 @@ void testPartialFailure() {
148148
fail("An AssertionFailedError should have been thrown");
149149
}
150150
}
151+
152+
@Test
153+
void testFailureWithEmptyCases() {
154+
TestResult result = new TestResult();
155+
result.setId("testFailureWithEmptyCases");
156+
result.setSuccess(false);
157+
result.setTestCaseResults(List.of());
158+
159+
boolean failed = false;
160+
try {
161+
Assertions.assertSuccess(result);
162+
} catch (Error error) {
163+
failed = true;
164+
assertInstanceOf(AssertionFailedError.class, error);
165+
assertEquals("Test 'testFailureWithEmptyCases' is not a success, but has no failure details", error.getMessage());
166+
}
167+
if (!failed) {
168+
fail("An AssertionFailedError should have been thrown");
169+
}
170+
171+
failed = false;
172+
try {
173+
Assertions.assertSuccess(result, "op1");
174+
} catch (Error error) {
175+
failed = true;
176+
assertInstanceOf(AssertionFailedError.class, error);
177+
assertEquals("Test 'testFailureWithEmptyCases' has no test case for operation 'op1'", error.getMessage());
178+
}
179+
if (!failed) {
180+
fail("An AssertionFailedError should have been thrown");
181+
}
182+
}
151183
}

src/test/java/io/github/microcks/testcontainers/MicrocksContainerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ private void testMicrocksContractTestingFunctionality(MicrocksContainer microcks
318318
// First test should fail with validation failure messages.
319319
TestResult testResult = microcks.testEndpoint(testRequest);
320320

321-
System.err.println(microcks.getLogs());
322-
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
323-
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(testResult));
321+
// System.err.println(microcks.getLogs());
322+
// ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
323+
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(testResult));
324324

325325
assertFalse(testResult.isSuccess());
326326
assertEquals("http://bad-impl:3001", testResult.getTestedEndpoint());

0 commit comments

Comments
 (0)