get_test.RdThe returned function can be executed. If that is done within a testthat::Reporter, the results will be reported accordingly. Without reporter, the test runs silently if successful and stops if it fails.
get_test(object)the test (function)
f <- function(x) x^2
test(f) <- function() {
context("f")
test_that("correct result for complex number", {
expect_equal(f(1i), -1 + 0i)
})
}
get_test(f)
#> function ()
#> {
#> context("f")
#> test_that("correct result for complex number", {
#> expect_equal(f(0+1i), -1 + (0+0i))
#> })
#> }
#> <environment: 0x563e5f0d5230>
library(testthat)
## execute the test
get_test(f)()
#> Test passed with 1 success 🌈.
with_reporter("summary", get_test(f)())
#> f: .
#> ══ DONE ════════════════════════════════════════════════════════════════════════