Execute code in the specified file, displaying results using a reporter. Use this function when you want to run a single file's worth of tests. You are responsible for ensuring that the functions to test are available in the global environment.

test_file(path, reporter = default_reporter(), env = test_env(),
  start_end_reporter = TRUE, load_helpers = TRUE,
  encoding = "unknown", wrap = TRUE)

Arguments

path

Path to file.

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.

start_end_reporter

Should the reporters start_reporter() and end_reporter() methods be called? For expert use only.

load_helpers

Source helper files before running the tests? See source_test_helpers() for more details.

encoding

Deprecated. All files now assumed to be UTF-8.

wrap

Automatically wrap all code within test_that()? This ensures that all expectations are reported, even if outside a test block.

Value

Invisibily, a list with one element for each test.

Examples

path <- testthat_example("success") test_file(path, reporter = "minimal")
#> .SW...
# test_file() invisibly returns a list, with one element for each test. # This can be useful if you want to compute on your test results. out <- test_file(path, reporter = "minimal")
#> .SW...
str(out[[1]])
#> List of 7 #> $ file : chr "test-success.R" #> $ context: NULL #> $ test : chr "one plus one is two" #> $ user : num 0 #> $ system : num 0 #> $ real : num 0.001 #> $ results:List of 1 #> ..$ :List of 7 #> .. ..$ message : chr "1 + 1 not equal to 2.\nEqual" #> .. ..$ srcref : 'srcref' int [1:8] 2 3 2 24 3 24 2 2 #> .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x4b34070> #> .. ..$ expectation_calls:List of 1 #> .. .. ..$ : language expect_equal(1 + 1, 2) #> .. .. .. ..- attr(*, "srcref")= 'srcref' int [1:8] 2 3 2 24 3 24 2 2 #> .. .. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x4b34070> #> .. .. ..- attr(*, "start_frame")= num 65 #> .. ..$ call :List of 1 #> .. .. ..$ : language expect_equal(1 + 1, 2) #> .. .. .. ..- attr(*, "srcref")= 'srcref' int [1:8] 2 3 2 24 3 24 2 2 #> .. .. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x4b34070> #> .. .. ..- attr(*, "start_frame")= num 65 #> .. ..$ start_frame : num 65 #> .. ..$ end_frame : num 65 #> .. ..$ test : chr "one plus one is two" #> .. ..- attr(*, "class")= chr [1:3] "expectation_success" "expectation" "condition"