Run unit tests with testthat without packaging
You can run tests with testthat::test_dir()
or testthat::test_file()
. None of them depend on the code in the package, or using devtools, only testthat .
There are several requirements for structuring your code. If it were me, I would create a directory tests
and add test scripts there, which would look something like this:
|- my_shiny_app
| |- app.R
| |- tests
| |- test_foo.R
| |- test_bar.R
Then you can run tests with test_dir('tests')
if you are in the directory my_shiny_app
.
In your test scripts, they will have the same structures that they have for packages , but you would replace the invocation with the library()
link in the source()
file in which your functions are defined.
source to share
If you have multiple functions without a package structure, it is better to write individual test files manually (for example, with a simple if / errors checking system) that you invoke with Rscript test_file1.R
.
If you start using the package format instead (which would be useful for future "safe" development) and you still don't want to use testthat
, I advise you to follow this blog post: here
source to share