Skip to content

Commit 0bb14a3

Browse files
core: steps include exception name (#1579)
1 parent cd53164 commit 0bb14a3

5 files changed

Lines changed: 44 additions & 16 deletions

File tree

webtau-core/src/main/java/org/testingisdocumenting/webtau/reporter/WebTauStep.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,15 @@ private void fail(Throwable t) {
618618
if (t instanceof AssertionTokenizedError) {
619619
exceptionTokenizedMessage = ((AssertionTokenizedError) t).getTokenizedMessage();
620620
} else {
621-
exceptionTokenizedMessage = tokenizedMessage().error(t.getMessage());
621+
exceptionTokenizedMessage = tokenizedMessage().error(exceptionMessage(t));
622622
}
623623
}
624624

625+
private String exceptionMessage(Throwable t) {
626+
String message = t.getMessage();
627+
return "<" + t.getClass().getSimpleName() + ">" + (message != null ? " " + message : "");
628+
}
629+
625630
private TokenizedMessage replaceValuesFirstLinesOnlyWithFull(TokenizedMessage message) {
626631
TokenizedMessage copy = new TokenizedMessage();
627632
for (MessageToken messageToken : message) {

webtau-core/src/test/groovy/org/testingisdocumenting/webtau/reporter/ConsoleStepReporterTest.groovy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
5959

6060
expectReport(Integer.MAX_VALUE, '> top level action\n' +
6161
' X failed validation:\n' +
62-
' line1\n' +
62+
' <AssertionError> line1\n' +
6363
' line2 (0ms)\n' +
6464
'X failed top level action (0ms)') {
6565
topLevelStep.execute(StepReportOptions.REPORT_ALL)
@@ -72,7 +72,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
7272

7373
expectReport(Integer.MAX_VALUE, '> top level action\n' +
7474
' X failed validation:\n' +
75-
' line1\n' +
75+
' <RuntimeException> line1\n' +
7676
' line2 (0ms)\n' +
7777
'X failed top level action (0ms)') {
7878
topLevelStep.execute(StepReportOptions.REPORT_ALL)
@@ -84,7 +84,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
8484
def topLevelStep = createStepWithNestedException(new RuntimeException('single line error'))
8585

8686
expectReport(Integer.MAX_VALUE, '> top level action\n' +
87-
' X failed validation: single line error (0ms)\n' +
87+
' X failed validation: <RuntimeException> single line error (0ms)\n' +
8888
'X failed top level action (0ms)') {
8989
topLevelStep.execute(StepReportOptions.REPORT_ALL)
9090
}
@@ -112,7 +112,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
112112
}
113113

114114
expectReport(Integer.MAX_VALUE, '> action\n' +
115-
'X failed action: error (250ms)') {
115+
'X failed action: <RuntimeException> error (250ms)') {
116116
action.execute(StepReportOptions.REPORT_ALL)
117117
}
118118
}
@@ -218,7 +218,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
218218
' . completed repeat (0ms)\n' +
219219
' . completed repeat #1 (0ms)\n' +
220220
' > 2/5\n' +
221-
' X failed repeat #2: no file found (0ms)\n' +
221+
' X failed repeat #2: <RuntimeException> no file found (0ms)\n' +
222222
' > 3/5\n' +
223223
' . 3/5 (0ms)\n' +
224224
' > 4/5\n' +
@@ -240,7 +240,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
240240

241241
expectReport(1,
242242
'> top level action\n' +
243-
'X failed top level action: dummy out of memory (0ms)') {
243+
'X failed top level action: <RuntimeException> dummy out of memory (0ms)') {
244244
executeNestedSteps()
245245
}
246246

@@ -249,7 +249,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
249249
' > second level action\n' +
250250
' . second level action completed (0ms)\n' +
251251
' > second level action with error\n' +
252-
' X failed second level action with error: dummy out of memory (0ms)\n' +
252+
' X failed second level action with error: <RuntimeException> dummy out of memory (0ms)\n' +
253253
'X failed top level action (0ms)') {
254254
executeNestedSteps()
255255
}
@@ -259,7 +259,7 @@ class ConsoleStepReporterTest implements ConsoleOutput {
259259
' . second level action completed (0ms)\n' +
260260
' > second level action with error\n' +
261261
' > third level action\n' +
262-
' X failed third level action: dummy out of memory (0ms)\n' +
262+
' X failed third level action: <RuntimeException> dummy out of memory (0ms)\n' +
263263
' X failed second level action with error (0ms)\n' +
264264
'X failed top level action (0ms)') {
265265
executeNestedSteps()

webtau-core/src/test/groovy/org/testingisdocumenting/webtau/reporter/WebTauStepTest.groovy

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.testingisdocumenting.webtau.reporter
1919

2020
import org.junit.BeforeClass
2121
import org.junit.Test
22-
import org.testingisdocumenting.webtau.WebTauCore
2322
import org.testingisdocumenting.webtau.cfg.WebTauConfig
2423
import org.testingisdocumenting.webtau.console.ConsoleOutputs
2524
import org.testingisdocumenting.webtau.data.render.PrettyPrinter
@@ -29,11 +28,10 @@ import org.testingisdocumenting.webtau.testutils.TestConsoleOutput
2928
import java.util.function.Supplier
3029

3130
import static java.util.stream.Collectors.*
32-
import static org.testingisdocumenting.webtau.Matchers.code
33-
import static org.testingisdocumenting.webtau.Matchers.throwException
34-
import static org.testingisdocumenting.webtau.WebTauCore.tokenizedMessage
31+
import static org.testingisdocumenting.webtau.WebTauCore.*
3532
import static org.testingisdocumenting.webtau.reporter.StepReportOptions.*
3633
import static org.testingisdocumenting.webtau.testutils.TestConsoleOutput.runAndValidateOutput
34+
import static org.testingisdocumenting.webtau.testutils.TestConsoleOutput.runExpectExceptionAndValidateOutput
3735

3836
class WebTauStepTest {
3937
static WebTauStep rootStep
@@ -156,7 +154,7 @@ class WebTauStepTest {
156154
}.execute(REPORT_ALL)
157155
}
158156

159-
runAndValidateOutput(WebTauCore.contain("failed repeat #8: unknown failure")) {
157+
runAndValidateOutput(contain("failed repeat #8: <RuntimeException> unknown failure")) {
160158
repeatStep.execute(REPORT_ALL)
161159
}
162160

@@ -173,6 +171,30 @@ class WebTauStepTest {
173171
assert steps[1].completionMessage.toString() == "done c1 action"
174172
}
175173

174+
@Test
175+
void "should include exception name"() {
176+
def step = createStep("exception step action") {
177+
throw new NullPointerException()
178+
}
179+
180+
runExpectExceptionAndValidateOutput(NullPointerException, "> exception step action\n" +
181+
"X failed exception step action: <NullPointerException> (Xms)") {
182+
step.execute(REPORT_ALL)
183+
}
184+
}
185+
186+
@Test
187+
void "should include exception name and message when present"() {
188+
def step = createStep("exception step action") {
189+
throw new ArrayIndexOutOfBoundsException("range")
190+
}
191+
192+
runExpectExceptionAndValidateOutput(ArrayIndexOutOfBoundsException, "> exception step action\n" +
193+
"X failed exception step action: <ArrayIndexOutOfBoundsException> range (Xms)") {
194+
step.execute(REPORT_ALL)
195+
}
196+
}
197+
176198
@Test
177199
void "should throw reduced message when console reporters present"() {
178200
try {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Add: [WebTau steps](report/steps) include exception name to help with cases when no exception message is present

webtau-report/src/test/groovy/org/testingisdocumenting/webtau/report/ConsoleReportGeneratorTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ class ConsoleReportGeneratorTest implements ConsoleOutput {
112112
output.should == '> do x\n' +
113113
' > nested do x\n' +
114114
' nestedKey: "value1"\n' +
115-
' X failed nested do x: nested failed step (Xms)\n' +
115+
' X failed nested do x: <RuntimeException> nested failed step (Xms)\n' +
116116
' outerKey: "value1"\n' +
117117
'X failed do x (Xms)\n' +
118118
'\n' +
119119
'you have 1 errored test(s):\n' +
120120
'[x] with nested (dummy)\n' +
121121
'X failed do x (Xms)\n' +
122-
' X failed nested do x: nested failed step (Xms)\n' +
122+
' X failed nested do x: <RuntimeException> nested failed step (Xms)\n' +
123123
' nestedKey: "value1"\n' +
124124
' outerKey: "value1"\n' +
125125
'java.lang.RuntimeException: nested failed step\n' +

0 commit comments

Comments
 (0)