Skip to content
This repository

Enhanced JUnit Exception Reporting #185

Closed
wants to merge 2 commits into from

3 participants

Klaus Bayrhammer Aslak Hellesøy David Kowis
Klaus Bayrhammer

The error reporting (at least in Intellij) had a problem tagging a scenario as failed when a step in this scenario failed (see screenshots).

BeforeFix:
http://rapidshare.com/files/2746712222/JUnitBefore.png

AfterFix:
http://rapidshare.com/files/3491825542/JUnitEnhancedScenarioInformation.png

Aslak Hellesøy

Awesome! This bug has annoyed me for a while.

David Kowis
Collaborator

How does it behave when a Before hook fails? After hook?

Just curious.

Klaus Bayrhammer

If the before hook fails, the scenario is tagged as "failed", steps are tagged as "skipped"
(see http://rapidshare.com/files/4205200393/BeforeHookFails.png)

If the after hook fails the scenario is tagged as "failed", all steps are tagged as "passed"
(see http://rapidshare.com/files/1265594566/AfterHookFails.png)

Aslak Hellesøy aslakhellesoy closed this in 89587bb February 05, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
7  junit/src/main/java/cucumber/junit/JUnitReporter.java
@@ -68,10 +68,9 @@ public void result(Result result) {
68 68
                     stepNotifier.addFailure(error);
69 69
                 }
70 70
                 stepNotifier.fireTestFinished();
71  
-            } else {
72  
-                if (error != null) {
73  
-                    executionUnitNotifier.addFailure(error);
74  
-                }
  71
+            }
  72
+            if (error != null) {
  73
+                executionUnitNotifier.addFailure(error);
75 74
             }
76 75
         }
77 76
         if(steps.isEmpty()) {
54  junit/src/test/java/cucumber/junit/JUnitReporterTest.java
... ...
@@ -0,0 +1,54 @@
  1
+package cucumber.junit;
  2
+
  3
+import static org.junit.Assert.assertEquals;
  4
+import static org.mockito.Mockito.mock;
  5
+import static org.mockito.Mockito.verify;
  6
+import static org.mockito.Mockito.when;
  7
+
  8
+import org.junit.Before;
  9
+import org.junit.Test;
  10
+import org.junit.runner.Description;
  11
+import org.junit.runner.notification.Failure;
  12
+import org.junit.runner.notification.RunNotifier;
  13
+import org.mockito.ArgumentCaptor;
  14
+
  15
+import gherkin.formatter.Formatter;
  16
+import gherkin.formatter.Reporter;
  17
+import gherkin.formatter.model.Result;
  18
+
  19
+public class JUnitReporterTest
  20
+{
  21
+
  22
+    private JUnitReporter jUnitReporter;
  23
+
  24
+    @Before
  25
+    public void setUp()
  26
+    {
  27
+        Formatter formatter = mock(Formatter.class);
  28
+        Reporter reporter = mock(Reporter.class);
  29
+        
  30
+        jUnitReporter = new JUnitReporter(reporter, formatter);
  31
+    }
  32
+
  33
+    @Test
  34
+    public void resultWithError() {
  35
+        Result result = mock(Result.class);
  36
+        Throwable exception = mock(Throwable.class);
  37
+        when(result.getError()).thenReturn(exception);
  38
+
  39
+        RunNotifier runNotifier = mock(RunNotifier.class);
  40
+        ExecutionUnitRunner executionUnitRunner = mock(ExecutionUnitRunner.class);
  41
+        Description description = mock(Description.class);
  42
+        when(executionUnitRunner.getDescription()).thenReturn(description);
  43
+        jUnitReporter.startExecutionUnit(executionUnitRunner, runNotifier);
  44
+
  45
+        jUnitReporter.result(result);
  46
+
  47
+        ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
  48
+        verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
  49
+
  50
+        Failure failure = failureArgumentCaptor.getValue();
  51
+        assertEquals(description, failure.getDescription());
  52
+        assertEquals(exception, failure.getException());
  53
+    }
  54
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.