Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JUnit/TestNG] Always print snippets for undefined steps
- Loading branch information
1 parent
c671ccc
commit 93659b9
Showing
6 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/main/java/cucumber/runtime/formatter/UndefinedStepsPrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cucumber.runtime.formatter; | ||
|
||
import cucumber.api.event.EventHandler; | ||
import cucumber.api.event.EventListener; | ||
import cucumber.api.event.EventPublisher; | ||
import cucumber.api.event.TestRunFinished; | ||
import cucumber.runtime.UndefinedStepsTracker; | ||
|
||
import java.io.PrintStream; | ||
import java.util.List; | ||
|
||
class UndefinedStepsPrinter implements EventListener { | ||
|
||
private final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker(); | ||
|
||
private final PrintStream out; | ||
|
||
public UndefinedStepsPrinter() { | ||
this.out = System.out; | ||
} | ||
|
||
private void print() { | ||
printSnippets(); | ||
} | ||
|
||
private void printSnippets() { | ||
List<String> snippets = undefinedStepsTracker.getSnippets(); | ||
if (!snippets.isEmpty()) { | ||
out.append("\n"); | ||
out.println("There were undefined steps. You can implement missing steps with the snippets below:"); | ||
out.println(); | ||
for (String snippet : snippets) { | ||
out.println(snippet); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void setEventPublisher(EventPublisher publisher) { | ||
undefinedStepsTracker.setEventPublisher(publisher); | ||
publisher.registerHandlerFor(TestRunFinished.class, new EventHandler<TestRunFinished>() { | ||
@Override | ||
public void receive(TestRunFinished event) { | ||
print(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters