| CucumberProgressReporter | R Documentation |
A reporter that prints step-by-step progress to the console, mimicking testthat::ProgressReporter but with visibility into individual Gherkin steps.
Prints each step as it executes with a status indicator, grouped under scenario and feature headers similar to testthat's output:
✓ for passed steps (green)
✗ for failed/errored steps (red)
Feature: Addition
Scenario: Add two numbers
[x] Given I have entered 50 into the calculator
[x] Given I have entered 70 into the calculator
[x] When I press add
[x] Then the result should be 120 on the screen
Pass a reporter instance to test() or run():
# Step-level detail
cucumber::test("tests/acceptance", reporter = cucumber::CucumberProgressReporter$new())
# testthat reporters still work, reporting at the scenario level only
cucumber::test("tests/acceptance", reporter = testthat::ProgressReporter$new())
# Silent mode
cucumber::test("tests/acceptance", reporter = testthat::SilentReporter$new())
# From within a test file
cucumber::run(reporter = cucumber::CucumberProgressReporter$new())
Extend CucumberReporter to build your own:
HTMLReporter <- R6::R6Class(
"HTMLReporter",
inherit = cucumber::CucumberReporter,
public = list(
html_output = character(),
start_feature = function(feature_name) {
super$start_feature(feature_name)
self$html_output <- c(self$html_output, sprintf("<h2>%s</h2>", feature_name))
},
end_step = function(step) {
super$end_step(step)
status_class <- step$status %||% "passed"
self$html_output <- c(
self$html_output,
sprintf('<div class="step %s">%s %s</div>', status_class, step$keyword, step$text)
)
},
end_reporter = function() {
if (!is.null(super$end_reporter)) super$end_reporter()
writeLines(self$html_output, "test-report.html")
}
)
)
When end_step() is called, the step object contains:
keyword - The step keyword (Given, When, Then, etc.)
text - The step text
status - One of "passed", "failed", or "error"
error - The error object if the step failed or errored (NULL otherwise)
duration - Execution time in seconds
data_table - Data table if present (NULL otherwise)
docstring - Docstring if present (NULL otherwise)
testthat::Reporter -> cucumber::CucumberReporter -> CucumberProgressReporter
show_praiseWhether to show praise messages
step_countNumber of steps executed
step_passedNumber of steps that passed
step_failedNumber of steps that failed
current_scenarioName of the scenario currently executing
current_stepsSteps executed so far in the current scenario
failuresRecorded failures for the end-of-run summary
step_erroredWhether end_step already rendered an error this scenario
num_colorsTerminal color support captured at construction
reporter_max_docstring_linesMax docstring lines to print per step
reporter_max_table_linesMax data table rows to print per step
testthat::Reporter$.start_context()testthat::Reporter$cat_line()testthat::Reporter$cat_tight()testthat::Reporter$end_context()testthat::Reporter$end_context_if_started()testthat::Reporter$end_file()testthat::Reporter$end_test()testthat::Reporter$is_full()testthat::Reporter$local_user_output()testthat::Reporter$rule()testthat::Reporter$start_context()testthat::Reporter$start_file()testthat::Reporter$start_reporter()testthat::Reporter$update()new()Initialize the reporter
CucumberProgressReporter$new(
show_praise = TRUE,
reporter_max_docstring_lines = getOption("cucumber.reporter_max_docstring_lines", Inf),
reporter_max_table_lines = getOption("cucumber.reporter_max_table_lines", Inf),
...
)show_praiseWhether to show praise (default TRUE)
reporter_max_docstring_linesMax docstring lines to print for a step before
truncating. Defaults to the cucumber.reporter_max_docstring_lines option, or
Inf (print in full) if unset.
reporter_max_table_linesMax data table rows to print for a step before
truncating. Defaults to the cucumber.reporter_max_table_lines option, or Inf
(print in full) if unset.
...Additional arguments passed to parent
start_feature()Start a feature
CucumberProgressReporter$start_feature(feature_name)
feature_nameName of the feature
end_feature()End the current feature
CucumberProgressReporter$end_feature()
start_test()Start a test (called by testthat for each scenario)
CucumberProgressReporter$start_test(context, test)
contextTest context
testTest name (will be "Scenario: <name>")
add_result()Add a result (warning, skip, failure, etc.)
CucumberProgressReporter$add_result(context, test, result)
contextTest context
testTest object
resultTest result object
start_step()Start a step
CucumberProgressReporter$start_step(step)
stepPickle step object
end_step()End a step and print its result
CucumberProgressReporter$end_step(step)
stepPickle step object with execution results
print_step_args()Print a step's docstring and/or data table arguments, indented and
truncated to reporter_max_docstring_lines / reporter_max_table_lines
CucumberProgressReporter$print_step_args(step)
stepPickle step object
end_reporter()Print summary at the end (called by testthat)
CucumberProgressReporter$end_reporter()
clone()The objects of this class are cloneable with this method.
CucumberProgressReporter$clone(deep = FALSE)
deepWhether to make a deep clone.
CucumberReporter
## Not run:
# Use with cucumber::test()
cucumber::test(
"tests/acceptance",
reporter = cucumber::CucumberProgressReporter$new()
)
# Or without praise messages
cucumber::test(
"tests/acceptance",
reporter = cucumber::CucumberProgressReporter$new(show_praise = FALSE)
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.