It runs tests from specifications in .feature files found in the path.
To run Cucumber tests alongside testthat tests, see cucumber::run().
Usage
test(
path = "tests/acceptance",
filter = NULL,
tags = NULL,
reporter = get_reporter(),
env = NULL,
load_helpers = TRUE,
stop_on_failure = TRUE,
stop_on_warning = FALSE,
...
)Arguments
- path
Path to directory containing tests.
- filter
If not NULL, only features with file names matching this regular expression will be executed. Matching is performed on the file name after it's stripped of ".feature".
If not NULL, filter scenarios by tag expression string (e.g.,
"@smoke and not @slow","@gui or @database"). Tag expressions supportand,or,notoperators and parentheses for grouping.- reporter
Reporter to use to summarise output. Can be supplied as a string (e.g. "summary") or as an R6 object (e.g.
SummaryReporter$new()).See Reporter for more details and a list of built-in reporters.
- env
Environment in which to execute the tests. Expert use only.
- load_helpers
Source helper files before running the tests?
- stop_on_failure
If
TRUE, throw an error if any tests fail.- stop_on_warning
If
TRUE, throw an error if any tests generate warnings.- ...
Additional arguments passed to
grepl()to control filtering.
Good Practices
Use a separate directory for your acceptance tests, e.g.
tests/acceptance.It's not prohibited to use
tests/testthatdirectory, but it's not recommended as those tests serve a different purpose and are better run separately, especially if acceptance tests take longer to run than unit tests.If you want to run Cucumber tests alongside
testthattests, you can usecucumber::run()in one of thetest-*.Rfiles in yourtests/testthatdirectory.Use
setup-*.Rfiles for callingstep(),define_parameter_type()andhook()to leverage testthat loading mechanism.If your
step(),define_parameter_type()andhook()are called from somewhere else, you are responsible for loading them.Read more about testthat special files in the testthat documentation.
Use
test-*.Rfiles to test the support code you might have implemented that is used to run Cucumber tests.Those tests won't be run when calling
test(). To run those tests usetestthat::test_dir("tests/acceptance").
Examples
if (FALSE) { # \dontrun{
cucumber::test("tests/acceptance")
cucumber::test("tests/acceptance", filter = "addition|multiplication")
# Tag expressions
cucumber::test("tests/acceptance", tags = "@smoke")
cucumber::test("tests/acceptance", tags = "@smoke and @fast")
cucumber::test("tests/acceptance", tags = "@wip and not @slow")
cucumber::test("tests/acceptance", tags = "(@smoke or @ui) and (not @slow)")
} # }
