I have R code (not a package) which I would like to cover with acceptance tests using testthat with output being used in Jenkins.
I can start with two files which demonstrate the code structure:
# -- test.R
source("test-mulitplication.R")
# -- test-mulitplication.R
library(testthat)
test_that("Multipilation works ", {
res <- 5 * 2
expect_equal(res, 10)
})
After the run I would like to get an xml file with results per test file or all tests in a single file.
I noticed there is a reporter
capability within testthat, but most of it seems to be internal to the package. It is not clear how to save test results and how flexible is the functionality.
Unfortunately documentation on that part is not complete.
EDIT
I have now found a way to test the directory with better syntax and option for junit output:
# -- tests/accpetance-tests.R
options(testthat.junit.output_file = "test-out.xml")
test_dir("tests/")
# -- tests/test-mulitplication.R
library(testthat)
test_that("Multipilation works ", {
res <- 5 * 2
expect_equal(res, 10)
})
This I believe produces an XML object inside the reporter, but I still don't see how to save it to a file.
I tried to wrap the test_dir
call with with_reporter
, but that does not do much.