Skip to content
Browse files

Report summaries and in the same way as the CLI

  • Loading branch information...
1 parent 545ecf5 commit 3e4dae2c35f99d424f7a1a5f447ba36aced51aa1 @aslakhellesoy aslakhellesoy committed
View
1 History.md
@@ -1,6 +1,7 @@
## [1-1-6-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...master)
* [Core, Java] Log a warning when more than one IoC dependency is found in the classpath ([#594](https://github.com/cucumber/cucumber-jvm/pull/594) Ariel Kogan)
+* [JUnit,TestNG] Report summaries and `.cucumber/stepdefs.json` in the same way as the CLI (Aslak Hellesøy)
## [1.1.5](https://github.com/cucumber/cucumber-jvm/compare/v1.1.4...v1.1.5) (2013-09-14)
View
2 android/AndroidManifest.xml
@@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1.5" package="cucumber.api.android">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1.6-SNAPSHOT" package="cucumber.api.android">
</manifest>
View
1 core/src/main/java/cucumber/api/cli/Main.java
@@ -22,7 +22,6 @@ public static void run(String[] argv, ClassLoader classLoader) throws IOExceptio
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
- runtime.writeStepdefsJson();
runtime.run();
System.exit(runtime.exitStatus());
}
View
3 core/src/main/java/cucumber/runtime/Glue.java
@@ -1,5 +1,6 @@
package cucumber.runtime;
+import cucumber.runtime.io.ResourceLoader;
import gherkin.I18n;
import gherkin.formatter.model.Step;
@@ -24,5 +25,5 @@
StepDefinitionMatch stepDefinitionMatch(String uri, Step step, I18n i18n);
- void writeStepdefsJson(List<String> featurePaths, URL dotCucumber) throws IOException;
+ void writeStepdefsJson(ResourceLoader resourceLoader, List<String> featurePaths, URL dotCucumber);
}
View
32 core/src/main/java/cucumber/runtime/Runtime.java
@@ -3,7 +3,6 @@
import cucumber.api.Pending;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.model.CucumberFeature;
-import cucumber.runtime.snippets.SummaryPrinter;
import cucumber.runtime.xstream.LocalizedXStreams;
import gherkin.I18n;
import gherkin.formatter.Argument;
@@ -42,7 +41,7 @@
private static final Object DUMMY_ARG = new Object();
private static final byte ERRORS = 0x1;
- private final SummaryCounter summaryCounter;
+ private final Stats stats;
final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();
private final Glue glue;
@@ -83,7 +82,7 @@ public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collectio
this.runtimeOptions = runtimeOptions;
this.stopWatch = stopWatch;
this.glue = optionalGlue != null ? optionalGlue : new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader));
- this.summaryCounter = new SummaryCounter(runtimeOptions.isMonochrome());
+ this.stats = new Stats(runtimeOptions.isMonochrome());
for (Backend backend : backends) {
backend.loadGlue(glue, runtimeOptions.getGlue());
@@ -103,7 +102,7 @@ public void addError(Throwable error) {
/**
* This is the main entry point. Used from CLI, but not from JUnit.
*/
- public void run() {
+ public void run() throws IOException {
for (CucumberFeature cucumberFeature : runtimeOptions.cucumberFeatures(resourceLoader)) {
run(cucumberFeature);
}
@@ -120,9 +119,18 @@ private void run(CucumberFeature cucumberFeature) {
cucumberFeature.run(formatter, reporter, this);
}
- private void printSummary() {
+ public void printSummary() {
// TODO: inject a SummaryPrinter in the ctor
new SummaryPrinter(System.out).print(this);
+ writeStepdefsJson();
+ }
+
+ void printStats(PrintStream out) {
+ stats.printStats(out);
+ }
+
+ private void writeStepdefsJson() {
+ glue.writeStepdefsJson(resourceLoader, runtimeOptions.getFeaturePaths(), runtimeOptions.getDotCucumber());
}
public void buildBackendWorlds(Reporter reporter, Set<Tag> tags) {
@@ -136,7 +144,7 @@ public void buildBackendWorlds(Reporter reporter, Set<Tag> tags) {
}
public void disposeBackendWorlds() {
- summaryCounter.addScenario(scenarioResult.getStatus());
+ stats.addScenario(scenarioResult.getStatus());
for (Backend backend : backends) {
backend.disposeWorld();
}
@@ -308,21 +316,13 @@ public static boolean isPending(Throwable t) {
return t.getClass().isAnnotationPresent(Pending.class) || Arrays.binarySearch(PENDING_EXCEPTIONS, t.getClass().getName()) >= 0;
}
- public void writeStepdefsJson() throws IOException {
- glue.writeStepdefsJson(runtimeOptions.getFeaturePaths(), runtimeOptions.getDotCucumber());
- }
-
- public void printSummary(PrintStream out) {
- summaryCounter.printSummary(out);
- }
-
private void addStepToCounterAndResult(Result result) {
scenarioResult.add(result);
- summaryCounter.addStep(result);
+ stats.addStep(result);
}
private void addHookToCounterAndResult(Result result) {
scenarioResult.add(result);
- summaryCounter.addHookTime(result.getDuration());
+ stats.addHookTime(result.getDuration());
}
}
View
17 core/src/main/java/cucumber/runtime/RuntimeGlue.java
@@ -2,7 +2,7 @@
import cucumber.runtime.autocomplete.MetaStepdef;
import cucumber.runtime.autocomplete.StepdefGenerator;
-import cucumber.runtime.io.FileResourceLoader;
+import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.io.URLOutputStream;
import cucumber.runtime.io.UTF8OutputStreamWriter;
import cucumber.runtime.model.CucumberFeature;
@@ -101,16 +101,21 @@ public StepDefinitionMatch stepDefinitionMatch(String uri, Step step, I18n i18n)
}
@Override
- public void writeStepdefsJson(List<String> featurePaths, URL dotCucumber) throws IOException {
+ public void writeStepdefsJson(ResourceLoader resourceLoader, List<String> featurePaths, URL dotCucumber) {
if (dotCucumber != null) {
- List<CucumberFeature> features = load(new FileResourceLoader(), featurePaths, NO_FILTERS);
+ List<CucumberFeature> features = load(resourceLoader, featurePaths, NO_FILTERS);
List<MetaStepdef> metaStepdefs = new StepdefGenerator().generate(stepDefinitionsByPattern.values(), features);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(metaStepdefs);
- Writer stepdefsJson = new UTF8OutputStreamWriter(new URLOutputStream(new URL(dotCucumber, "stepdefs.json")));
- stepdefsJson.append(json);
- stepdefsJson.close();
+ try {
+ URL stepdefsUrl = new URL(dotCucumber, "stepdefs.json");
+ Writer stepdefsJson = new UTF8OutputStreamWriter(new URLOutputStream(stepdefsUrl));
+ stepdefsJson.append(json);
+ stepdefsJson.close();
+ } catch (IOException e) {
+ throw new CucumberException("Failed to write stepdefs.json", e);
+ }
}
}
}
View
262 ...java/cucumber/runtime/SummaryCounter.java → ...src/main/java/cucumber/runtime/Stats.java
@@ -1,131 +1,131 @@
-package cucumber.runtime;
-
-import gherkin.formatter.AnsiFormats;
-import gherkin.formatter.Format;
-import gherkin.formatter.Formats;
-import gherkin.formatter.MonochromeFormats;
-import gherkin.formatter.model.Result;
-
-import java.io.PrintStream;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.Locale;
-
-public class SummaryCounter {
- public static final long ONE_SECOND = 1000000000;
- public static final long ONE_MINUTE = 60 * ONE_SECOND;
- public static final String PENDING = "pending";
- private SubCounts scenarioSubCounts = new SubCounts();
- private SubCounts stepSubCounts = new SubCounts();
- private long totalDuration = 0;
- private Formats formats;
- private Locale locale;
-
- public SummaryCounter(boolean monochrome) {
- this(monochrome, Locale.getDefault());
- }
-
- public SummaryCounter(boolean monochrome, Locale locale) {
- this.locale = locale;
- if (monochrome) {
- formats = new MonochromeFormats();
- } else {
- formats = new AnsiFormats();
- }
- }
-
- public void printSummary(PrintStream out) {
- if (stepSubCounts.getTotal() == 0) {
- out.println("0 Scenarios");
- out.println("0 Steps");
- } else {
- printScenarioCounts(out);
- printStepCounts(out);
- }
- printDuration(out);
- }
-
- private void printStepCounts(PrintStream out) {
- out.print(stepSubCounts.getTotal());
- out.print(" Steps (");
- printSubCounts(out, stepSubCounts);
- out.println(")");
- }
-
- private void printScenarioCounts(PrintStream out) {
- out.print(scenarioSubCounts.getTotal());
- out.print(" Scenarios (");
- printSubCounts(out, scenarioSubCounts);
- out.println(")");
- }
-
- private void printSubCounts(PrintStream out, SubCounts subCounts) {
- boolean addComma = false;
- addComma = printSubCount(out, subCounts.failed, Result.FAILED, addComma);
- addComma = printSubCount(out, subCounts.skipped, Result.SKIPPED.getStatus(), addComma);
- addComma = printSubCount(out, subCounts.pending, PENDING, addComma);
- addComma = printSubCount(out, subCounts.undefined, Result.UNDEFINED.getStatus(), addComma);
- addComma = printSubCount(out, subCounts.passed, Result.PASSED, addComma);
- }
-
- private boolean printSubCount(PrintStream out, int count, String type, boolean addComma) {
- if (count != 0) {
- if (addComma) {
- out.print(", ");
- }
- Format format = formats.get(type);
- out.print(format.text(count + " " + type));
- addComma = true;
- }
- return addComma;
- }
-
- private void printDuration(PrintStream out) {
- out.print(String.format("%dm", (totalDuration/ONE_MINUTE)));
- DecimalFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(locale));
- out.println(format.format(((double)(totalDuration%ONE_MINUTE))/ONE_SECOND) + "s");
- }
-
- public void addStep(Result result) {
- addResultToSubCount(stepSubCounts, result.getStatus());
- addTime(result.getDuration());
- }
-
- public void addScenario(String resultStatus) {
- addResultToSubCount(scenarioSubCounts, resultStatus);
- }
-
- public void addHookTime(Long duration) {
- addTime(duration);
- }
-
- private void addTime(Long duration) {
- totalDuration += duration != null ? duration : 0;
- }
-
- private void addResultToSubCount(SubCounts subCounts, String resultStatus) {
- if (resultStatus.equals(Result.FAILED)) {
- subCounts.failed++;
- } else if (resultStatus.equals(PENDING)) {
- subCounts.pending++;
- } else if (resultStatus.equals(Result.UNDEFINED.getStatus())) {
- subCounts.undefined++;
- } else if (resultStatus.equals(Result.SKIPPED.getStatus())) {
- subCounts.skipped++;
- } else if (resultStatus.equals(Result.PASSED)) {
- subCounts.passed++;
- }
- }
-}
-
-class SubCounts {
- public int passed = 0;
- public int failed = 0;
- public int skipped = 0;
- public int pending = 0;
- public int undefined = 0;
-
- public int getTotal() {
- return passed + failed + skipped + pending + undefined;
- }
-}
+package cucumber.runtime;
+
+import gherkin.formatter.AnsiFormats;
+import gherkin.formatter.Format;
+import gherkin.formatter.Formats;
+import gherkin.formatter.MonochromeFormats;
+import gherkin.formatter.model.Result;
+
+import java.io.PrintStream;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
+
+class Stats {
+ public static final long ONE_SECOND = 1000000000;
+ public static final long ONE_MINUTE = 60 * ONE_SECOND;
+ public static final String PENDING = "pending";
+ private SubCounts scenarioSubCounts = new SubCounts();
+ private SubCounts stepSubCounts = new SubCounts();
+ private long totalDuration = 0;
+ private Formats formats;
+ private Locale locale;
+
+ public Stats(boolean monochrome) {
+ this(monochrome, Locale.getDefault());
+ }
+
+ public Stats(boolean monochrome, Locale locale) {
+ this.locale = locale;
+ if (monochrome) {
+ formats = new MonochromeFormats();
+ } else {
+ formats = new AnsiFormats();
+ }
+ }
+
+ public void printStats(PrintStream out) {
+ if (stepSubCounts.getTotal() == 0) {
+ out.println("0 Scenarios");
+ out.println("0 Steps");
+ } else {
+ printScenarioCounts(out);
+ printStepCounts(out);
+ }
+ printDuration(out);
+ }
+
+ private void printStepCounts(PrintStream out) {
+ out.print(stepSubCounts.getTotal());
+ out.print(" Steps (");
+ printSubCounts(out, stepSubCounts);
+ out.println(")");
+ }
+
+ private void printScenarioCounts(PrintStream out) {
+ out.print(scenarioSubCounts.getTotal());
+ out.print(" Scenarios (");
+ printSubCounts(out, scenarioSubCounts);
+ out.println(")");
+ }
+
+ private void printSubCounts(PrintStream out, SubCounts subCounts) {
+ boolean addComma = false;
+ addComma = printSubCount(out, subCounts.failed, Result.FAILED, addComma);
+ addComma = printSubCount(out, subCounts.skipped, Result.SKIPPED.getStatus(), addComma);
+ addComma = printSubCount(out, subCounts.pending, PENDING, addComma);
+ addComma = printSubCount(out, subCounts.undefined, Result.UNDEFINED.getStatus(), addComma);
+ addComma = printSubCount(out, subCounts.passed, Result.PASSED, addComma);
+ }
+
+ private boolean printSubCount(PrintStream out, int count, String type, boolean addComma) {
+ if (count != 0) {
+ if (addComma) {
+ out.print(", ");
+ }
+ Format format = formats.get(type);
+ out.print(format.text(count + " " + type));
+ addComma = true;
+ }
+ return addComma;
+ }
+
+ private void printDuration(PrintStream out) {
+ out.print(String.format("%dm", (totalDuration / ONE_MINUTE)));
+ DecimalFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(locale));
+ out.println(format.format(((double) (totalDuration % ONE_MINUTE)) / ONE_SECOND) + "s");
+ }
+
+ public void addStep(Result result) {
+ addResultToSubCount(stepSubCounts, result.getStatus());
+ addTime(result.getDuration());
+ }
+
+ public void addScenario(String resultStatus) {
+ addResultToSubCount(scenarioSubCounts, resultStatus);
+ }
+
+ public void addHookTime(Long duration) {
+ addTime(duration);
+ }
+
+ private void addTime(Long duration) {
+ totalDuration += duration != null ? duration : 0;
+ }
+
+ private void addResultToSubCount(SubCounts subCounts, String resultStatus) {
+ if (resultStatus.equals(Result.FAILED)) {
+ subCounts.failed++;
+ } else if (resultStatus.equals(PENDING)) {
+ subCounts.pending++;
+ } else if (resultStatus.equals(Result.UNDEFINED.getStatus())) {
+ subCounts.undefined++;
+ } else if (resultStatus.equals(Result.SKIPPED.getStatus())) {
+ subCounts.skipped++;
+ } else if (resultStatus.equals(Result.PASSED)) {
+ subCounts.passed++;
+ }
+ }
+
+ class SubCounts {
+ public int passed = 0;
+ public int failed = 0;
+ public int skipped = 0;
+ public int pending = 0;
+ public int undefined = 0;
+
+ public int getTotal() {
+ return passed + failed + skipped + pending + undefined;
+ }
+ }
+}
View
8 ...mber/runtime/snippets/SummaryPrinter.java → ...java/cucumber/runtime/SummaryPrinter.java
@@ -1,4 +1,4 @@
-package cucumber.runtime.snippets;
+package cucumber.runtime;
import java.io.PrintStream;
import java.util.List;
@@ -12,14 +12,14 @@ public SummaryPrinter(PrintStream out) {
public void print(cucumber.runtime.Runtime runtime) {
out.println();
- printSummary(runtime);
+ printStats(runtime);
out.println();
printErrors(runtime);
printSnippets(runtime);
}
- private void printSummary(cucumber.runtime.Runtime runtime) {
- runtime.printSummary(out);
+ private void printStats(cucumber.runtime.Runtime runtime) {
+ runtime.printStats(out);
}
private void printErrors(cucumber.runtime.Runtime runtime) {
View
20 core/src/test/java/cucumber/runtime/RuntimeTest.java
@@ -16,12 +16,12 @@
import org.junit.internal.AssumptionViolatedException;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Properties;
import static cucumber.runtime.TestHelper.feature;
import static java.util.Arrays.asList;
@@ -180,7 +180,7 @@ public void strict_with_errors() {
}
@Test
- public void should_pass_if_no_features_are_found() {
+ public void should_pass_if_no_features_are_found() throws IOException {
ResourceLoader resourceLoader = createResourceLoaderThatFindsNoFeatures();
Runtime runtime = createStrictRuntime(resourceLoader);
@@ -211,7 +211,7 @@ public void should_add_passed_result_to_the_summary_counter() throws Exception {
runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 passed)%n" +
@@ -228,7 +228,7 @@ public void should_add_pending_result_to_the_summary_counter() throws Throwable
runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 pending)%n" +
@@ -245,7 +245,7 @@ public void should_add_failed_result_to_the_summary_counter() throws Throwable {
runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 failed)%n" +
@@ -261,7 +261,7 @@ public void should_add_ambiguous_match_as_failed_result_to_the_summary_counter()
runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 failed)%n" +
@@ -279,7 +279,7 @@ public void should_add_skipped_result_to_the_summary_counter() throws Throwable
runStep(reporter, runtime);
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 failed)%n" +
@@ -295,7 +295,7 @@ public void should_add_undefined_result_to_the_summary_counter() throws Throwabl
runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 undefined)%n" +
@@ -314,7 +314,7 @@ public void should_fail_the_scenario_if_before_fails() throws Throwable {
runtime.runBeforeHooks(reporter, Collections.<Tag>emptySet());
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 failed)%n" +
@@ -333,7 +333,7 @@ public void should_fail_the_scenario_if_after_fails() throws Throwable {
runStep(reporter, runtime);
runtime.runAfterHooks(reporter, Collections.<Tag>emptySet());
runtime.disposeBackendWorlds();
- runtime.printSummary(new PrintStream(baos));
+ runtime.printStats(new PrintStream(baos));
assertThat(baos.toString(), startsWith(String.format(
"1 Scenarios (1 failed)%n" +
View
344 .../cucumber/runtime/SummaryCounterTest.java → ...test/java/cucumber/runtime/StatsTest.java
@@ -1,172 +1,172 @@
-package cucumber.runtime;
-
-import static org.junit.Assert.assertThat;
-import static org.hamcrest.CoreMatchers.endsWith;
-import static org.hamcrest.CoreMatchers.startsWith;
-
-import gherkin.formatter.ansi.AnsiEscapes;
-import gherkin.formatter.model.Result;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.Locale;
-
-import org.junit.Test;
-
-public class SummaryCounterTest {
- public static final long ONE_MILLI_SECOND = 1000000;
- private static final long ONE_HOUR = 60 * SummaryCounter.ONE_MINUTE;
-
- @Test
- public void should_print_zero_scenarios_zero_steps_if_nothing_has_executed() {
- SummaryCounter counter = createMonochromeSummaryCounter();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), startsWith(String.format(
- "0 Scenarios%n" +
- "0 Steps%n")));
- }
-
- @Test
- public void should_only_print_sub_counts_if_not_zero() {
- SummaryCounter counter = createMonochromeSummaryCounter();
- Result passedResult = createResultWithStatus(Result.PASSED);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- counter.addStep(passedResult);
- counter.addStep(passedResult);
- counter.addStep(passedResult);
- counter.addScenario(Result.PASSED);
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), startsWith(String.format(
- "1 Scenarios (1 passed)%n" +
- "3 Steps (3 passed)%n")));
- }
-
- @Test
- public void should_print_sub_counts_in_order_failed_skipped_pending_undefined_passed() {
- SummaryCounter counter = createMonochromeSummaryCounter();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- addOneStepScenario(counter, Result.PASSED);
- addOneStepScenario(counter, Result.FAILED);
- addOneStepScenario(counter, SummaryCounter.PENDING);
- addOneStepScenario(counter, Result.UNDEFINED.getStatus());
- addOneStepScenario(counter, Result.SKIPPED.getStatus());
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), startsWith(String.format(
- "5 Scenarios (1 failed, 1 skipped, 1 pending, 1 undefined, 1 passed)%n" +
- "5 Steps (1 failed, 1 skipped, 1 pending, 1 undefined, 1 passed)%n")));
- }
-
- @Test
- public void should_print_sub_counts_in_order_failed_skipped_undefined_passed_in_color() {
- SummaryCounter counter = createColorSummaryCounter();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- addOneStepScenario(counter, Result.PASSED);
- addOneStepScenario(counter, Result.FAILED);
- addOneStepScenario(counter, SummaryCounter.PENDING);
- addOneStepScenario(counter, Result.UNDEFINED.getStatus());
- addOneStepScenario(counter, Result.SKIPPED.getStatus());
- counter.printSummary(new PrintStream(baos));
-
- String colorSubCounts =
- AnsiEscapes.RED + "1 failed" + AnsiEscapes.RESET + ", " +
- AnsiEscapes.CYAN + "1 skipped" + AnsiEscapes.RESET + ", " +
- AnsiEscapes.YELLOW + "1 pending" + AnsiEscapes.RESET + ", " +
- AnsiEscapes.YELLOW + "1 undefined" + AnsiEscapes.RESET + ", " +
- AnsiEscapes.GREEN + "1 passed" + AnsiEscapes.RESET;
- assertThat(baos.toString(), startsWith(String.format(
- "5 Scenarios (" + colorSubCounts + ")%n" +
- "5 Steps (" + colorSubCounts + ")%n")));
- }
-
- @Test
- public void should_print_zero_m_zero_s_if_nothing_has_executed() {
- SummaryCounter counter = createMonochromeSummaryCounter();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), endsWith(String.format(
- "0m0.000s%n")));
- }
-
- @Test
- public void should_include_hook_time_and_step_time_has_executed() {
- SummaryCounter counter = createMonochromeSummaryCounter();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- counter.addHookTime(ONE_MILLI_SECOND);
- counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
- counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
- counter.addHookTime(ONE_MILLI_SECOND);
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), endsWith(String.format(
- "0m0.004s%n")));
- }
-
- @Test
- public void should_print_minutes_seconds_and_milliseconds() {
- SummaryCounter counter = createMonochromeSummaryCounter();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- counter.addStep(new Result(Result.PASSED, SummaryCounter.ONE_MINUTE, null));
- counter.addStep(new Result(Result.PASSED, SummaryCounter.ONE_SECOND, null));
- counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), endsWith(String.format(
- "1m1.001s%n")));
- }
-
- @Test
- public void should_print_minutes_instead_of_hours() {
- SummaryCounter counter = createMonochromeSummaryCounter();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- counter.addStep(new Result(Result.PASSED, ONE_HOUR, null));
- counter.addStep(new Result(Result.PASSED, SummaryCounter.ONE_MINUTE, null));
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), endsWith(String.format(
- "61m0.000s%n")));
- }
-
- @Test
- public void should_use_locale_for_decimal_separator() {
- SummaryCounter counter = new SummaryCounter(true, Locale.GERMANY);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- counter.addStep(new Result(Result.PASSED, SummaryCounter.ONE_MINUTE, null));
- counter.addStep(new Result(Result.PASSED, SummaryCounter.ONE_SECOND, null));
- counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
- counter.printSummary(new PrintStream(baos));
-
- assertThat(baos.toString(), endsWith(String.format(
- "1m1,001s%n")));
- }
-
- private void addOneStepScenario(SummaryCounter counter, String status) {
- counter.addStep(createResultWithStatus(status));
- counter.addScenario(status);
- }
-
- private Result createResultWithStatus(String status) {
- return new Result(status, 0l, null);
- }
-
- private SummaryCounter createMonochromeSummaryCounter() {
- return new SummaryCounter(true, Locale.US);
- }
-
- private SummaryCounter createColorSummaryCounter() {
- return new SummaryCounter(false, Locale.US);
- }
-}
+package cucumber.runtime;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.startsWith;
+
+import gherkin.formatter.ansi.AnsiEscapes;
+import gherkin.formatter.model.Result;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Locale;
+
+import org.junit.Test;
+
+public class StatsTest {
+ public static final long ONE_MILLI_SECOND = 1000000;
+ private static final long ONE_HOUR = 60 * Stats.ONE_MINUTE;
+
+ @Test
+ public void should_print_zero_scenarios_zero_steps_if_nothing_has_executed() {
+ Stats counter = createMonochromeSummaryCounter();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), startsWith(String.format(
+ "0 Scenarios%n" +
+ "0 Steps%n")));
+ }
+
+ @Test
+ public void should_only_print_sub_counts_if_not_zero() {
+ Stats counter = createMonochromeSummaryCounter();
+ Result passedResult = createResultWithStatus(Result.PASSED);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ counter.addStep(passedResult);
+ counter.addStep(passedResult);
+ counter.addStep(passedResult);
+ counter.addScenario(Result.PASSED);
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), startsWith(String.format(
+ "1 Scenarios (1 passed)%n" +
+ "3 Steps (3 passed)%n")));
+ }
+
+ @Test
+ public void should_print_sub_counts_in_order_failed_skipped_pending_undefined_passed() {
+ Stats counter = createMonochromeSummaryCounter();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ addOneStepScenario(counter, Result.PASSED);
+ addOneStepScenario(counter, Result.FAILED);
+ addOneStepScenario(counter, Stats.PENDING);
+ addOneStepScenario(counter, Result.UNDEFINED.getStatus());
+ addOneStepScenario(counter, Result.SKIPPED.getStatus());
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), startsWith(String.format(
+ "5 Scenarios (1 failed, 1 skipped, 1 pending, 1 undefined, 1 passed)%n" +
+ "5 Steps (1 failed, 1 skipped, 1 pending, 1 undefined, 1 passed)%n")));
+ }
+
+ @Test
+ public void should_print_sub_counts_in_order_failed_skipped_undefined_passed_in_color() {
+ Stats counter = createColorSummaryCounter();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ addOneStepScenario(counter, Result.PASSED);
+ addOneStepScenario(counter, Result.FAILED);
+ addOneStepScenario(counter, Stats.PENDING);
+ addOneStepScenario(counter, Result.UNDEFINED.getStatus());
+ addOneStepScenario(counter, Result.SKIPPED.getStatus());
+ counter.printStats(new PrintStream(baos));
+
+ String colorSubCounts =
+ AnsiEscapes.RED + "1 failed" + AnsiEscapes.RESET + ", " +
+ AnsiEscapes.CYAN + "1 skipped" + AnsiEscapes.RESET + ", " +
+ AnsiEscapes.YELLOW + "1 pending" + AnsiEscapes.RESET + ", " +
+ AnsiEscapes.YELLOW + "1 undefined" + AnsiEscapes.RESET + ", " +
+ AnsiEscapes.GREEN + "1 passed" + AnsiEscapes.RESET;
+ assertThat(baos.toString(), startsWith(String.format(
+ "5 Scenarios (" + colorSubCounts + ")%n" +
+ "5 Steps (" + colorSubCounts + ")%n")));
+ }
+
+ @Test
+ public void should_print_zero_m_zero_s_if_nothing_has_executed() {
+ Stats counter = createMonochromeSummaryCounter();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), endsWith(String.format(
+ "0m0.000s%n")));
+ }
+
+ @Test
+ public void should_include_hook_time_and_step_time_has_executed() {
+ Stats counter = createMonochromeSummaryCounter();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ counter.addHookTime(ONE_MILLI_SECOND);
+ counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
+ counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
+ counter.addHookTime(ONE_MILLI_SECOND);
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), endsWith(String.format(
+ "0m0.004s%n")));
+ }
+
+ @Test
+ public void should_print_minutes_seconds_and_milliseconds() {
+ Stats counter = createMonochromeSummaryCounter();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ counter.addStep(new Result(Result.PASSED, Stats.ONE_MINUTE, null));
+ counter.addStep(new Result(Result.PASSED, Stats.ONE_SECOND, null));
+ counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), endsWith(String.format(
+ "1m1.001s%n")));
+ }
+
+ @Test
+ public void should_print_minutes_instead_of_hours() {
+ Stats counter = createMonochromeSummaryCounter();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ counter.addStep(new Result(Result.PASSED, ONE_HOUR, null));
+ counter.addStep(new Result(Result.PASSED, Stats.ONE_MINUTE, null));
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), endsWith(String.format(
+ "61m0.000s%n")));
+ }
+
+ @Test
+ public void should_use_locale_for_decimal_separator() {
+ Stats counter = new Stats(true, Locale.GERMANY);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ counter.addStep(new Result(Result.PASSED, Stats.ONE_MINUTE, null));
+ counter.addStep(new Result(Result.PASSED, Stats.ONE_SECOND, null));
+ counter.addStep(new Result(Result.PASSED, ONE_MILLI_SECOND, null));
+ counter.printStats(new PrintStream(baos));
+
+ assertThat(baos.toString(), endsWith(String.format(
+ "1m1,001s%n")));
+ }
+
+ private void addOneStepScenario(Stats counter, String status) {
+ counter.addStep(createResultWithStatus(status));
+ counter.addScenario(status);
+ }
+
+ private Result createResultWithStatus(String status) {
+ return new Result(status, 0l, null);
+ }
+
+ private Stats createMonochromeSummaryCounter() {
+ return new Stats(true, Locale.US);
+ }
+
+ private Stats createColorSummaryCounter() {
+ return new Stats(false, Locale.US);
+ }
+}
View
173 examples/java-calculator/.cucumber/stepdefs.json
@@ -0,0 +1,173 @@
+[
+ {
+ "steps": [
+ {
+ "name": "I add 4 and 5",
+ "args": [
+ {
+ "offset": 6,
+ "val": "4"
+ },
+ {
+ "offset": 12,
+ "val": "5"
+ }
+ ]
+ },
+ {
+ "name": "I add 4 and 7",
+ "args": [
+ {
+ "offset": 6,
+ "val": "4"
+ },
+ {
+ "offset": 12,
+ "val": "7"
+ }
+ ]
+ }
+ ],
+ "source": "^I add (\\d+) and (\\d+)$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "I ask if Jan 19, 2011 is in the past",
+ "args": [
+ {
+ "offset": 9,
+ "val": "Jan 19, 2011"
+ }
+ ]
+ }
+ ],
+ "source": "^I ask if (.+) is in the past$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "I pay 25",
+ "args": [
+ {
+ "offset": 6,
+ "val": "25"
+ }
+ ]
+ }
+ ],
+ "source": "^I pay (\\d+)$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "I press +",
+ "args": [
+ {
+ "offset": 8,
+ "val": "+"
+ }
+ ]
+ }
+ ],
+ "source": "^I press (.+)$",
+ "flags": ""
+ },
+ {
+ "steps": [],
+ "source": "^a calculator I just turned on$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "my change should be 4",
+ "args": [
+ {
+ "offset": 20,
+ "val": "4"
+ }
+ ]
+ }
+ ],
+ "source": "^my change should be (\\d+)$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "the following groceries:",
+ "args": []
+ }
+ ],
+ "source": "^the following groceries:$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "the previous entries:",
+ "args": []
+ }
+ ],
+ "source": "^the previous entries:$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "the result is 11",
+ "args": [
+ {
+ "offset": 14,
+ "val": "11"
+ }
+ ]
+ },
+ {
+ "name": "the result is 9",
+ "args": [
+ {
+ "offset": 14,
+ "val": "9"
+ }
+ ]
+ }
+ ],
+ "source": "^the result is (\\d+)$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "the result should be yes",
+ "args": [
+ {
+ "offset": 21,
+ "val": "yes"
+ }
+ ]
+ }
+ ],
+ "source": "^the result should be (.+)$",
+ "flags": ""
+ },
+ {
+ "steps": [
+ {
+ "name": "today is 2011-01-20",
+ "args": [
+ {
+ "offset": 9,
+ "val": "2011-01-20"
+ }
+ ]
+ }
+ ],
+ "source": "^today is (.+)$",
+ "flags": ""
+ }
+]
View
2 examples/java-calculator/src/test/java/cucumber/examples/java/calculator/RunCukesTest.java
@@ -5,6 +5,6 @@
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
-@CucumberOptions(format = "json:target/cucumber-report.json")
+@CucumberOptions(format = "json:target/cucumber-report.json", dotcucumber = ".cucumber")
public class RunCukesTest {
}
View
4 java/src/test/java/cucumber/runtime/java/JavaBackendTest.java
@@ -5,12 +5,12 @@
import cucumber.runtime.HookDefinition;
import cucumber.runtime.StepDefinition;
import cucumber.runtime.StepDefinitionMatch;
+import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.java.stepdefs.Stepdefs;
import gherkin.I18n;
import gherkin.formatter.model.Step;
import org.junit.Test;
-import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -81,7 +81,7 @@ public StepDefinitionMatch stepDefinitionMatch(String uri, Step step, I18n i18n)
}
@Override
- public void writeStepdefsJson(List<String> featurePaths, URL dotCucumber) throws IOException {
+ public void writeStepdefsJson(ResourceLoader resourceLoader, List<String> featurePaths, URL dotCucumber) {
throw new UnsupportedOperationException();
}
}
View
3 junit/src/main/java/cucumber/api/junit/Cucumber.java
@@ -13,7 +13,6 @@
import cucumber.runtime.junit.FeatureRunner;
import cucumber.runtime.junit.JUnitReporter;
import cucumber.runtime.model.CucumberFeature;
-import cucumber.runtime.snippets.SummaryPrinter;
import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
@@ -87,7 +86,7 @@ public void run(RunNotifier notifier) {
super.run(notifier);
jUnitReporter.done();
jUnitReporter.close();
- new SummaryPrinter(System.out).print(runtime);
+ runtime.printSummary();
}
private void addChildren(List<CucumberFeature> cucumberFeatures) throws InitializationError {
View
15 testng/src/main/java/cucumber/api/testng/AbstractTestNGCucumberTests.java
@@ -14,29 +14,28 @@
import org.testng.ITestResult;
import org.testng.annotations.Test;
+import java.io.IOException;
+
public abstract class AbstractTestNGCucumberTests implements IHookable {
- private final TestNgReporter reporter;
private final Runtime runtime;
- private final ClassLoader classLoader;
- private final ResourceLoader resourceLoader;
public AbstractTestNGCucumberTests() {
- classLoader = getClass().getClassLoader();
- resourceLoader = new MultiLoader(classLoader);
+ ClassLoader classLoader = getClass().getClassLoader();
+ ResourceLoader resourceLoader = new MultiLoader(classLoader);
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(getClass(), new Class[]{CucumberOptions.class});
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
- reporter = new TestNgReporter(System.out);
+ TestNgReporter reporter = new TestNgReporter(System.out);
runtimeOptions.getFormatters().add(reporter);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
}
@Test(groups = "cucumber", description = "Runs Cucumber Features")
- public void run_cukes() {
+ public void run_cukes() throws IOException {
runtime.run();
-
+ runtime.printSummary();
if (!runtime.getErrors().isEmpty()) {
throw new CucumberException(runtime.getErrors().get(0));
}

0 comments on commit 3e4dae2

Please sign in to comment.
Something went wrong with that request. Please try again.