简体   繁体   中英

How do I run an individual testthat test in R?

I want to use testthat for integration tests in an R package being installed into a Jupyter notebook environment. Practically, that means I don't want the tests run when the package is installed, but rather manually later, when the system is running.

I think that means I shouldn't put tests into a tests/testthat directory, but rather the R directory.

So, I still want all the expect_ functions, but how do I run a test? I'm not sure if I can specify a file or directory, because it will be after the package is installed, and I don't know what the current working directory or install directory will be.

From the testthat package . . .

If you're using testthat in a package, you should put your tests in tests/testthat. Each test file should start with test and end in .R or .r. To ensure R CMD check runs your tests, place the following code in tests/testthat.R:

library(testthat) ; library(yourpackage)

test_check("yourpackage")

It sounds like you should follow all the setup but leave the testthat.R file out of the directory. You can run the test_check("yourpackage") from the console or a script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM