I have tests for a package that check functions that may or may not return warnings, for example:
test_that("test", {
expect_true(is.na(log(NA)))
expect_true(is.na(log(-1)))
})
I am not interested in checking weather the warnings appeared. Is…
I am using the testthat library for unit testing in a R project. I want to test code that relies on database queries, but not test the actual queries themselves. In other words, I'd like to mock the database connections and queries (having them…
I am writing a script that ultimately returns a data frame. My question is around if there are any good practices on how to use a unit test package to make sure that the data frame that is returned is correct. (I'm a beginning R programmer, plus new…
I have a bunch of tests that I don't want them running during CRAN checks or Travis CI builds. They are either long-running, or they could cause transaction/concurrency conflicts writing to a networked database. What approach of separating them…
For a given installed package, how do I run its testthat tests? I'm not a developer of the installed package, I'm a user. I just want to run its test suite to confirm its tests pass in my environment. I've tried test_check and test_package but I…
I am calling a function from base in my code and I want to mock this function in my testthat unit test.
How can I do this?
library(testthat)
my.func <- function() {
return(Sys.info()["sysname"]) # e. g. "Linux"
}
my.func()
# sysname
# "Linux"…
I am using testthat to test a package with a file tree similar to the following:
.
├── data
│ └── testhaplom.out
├── inst
│ └── test
│ ├── test1.r
│ ├── tmp_S7byVksGRI6Q
│ │ └── testm.desc
…
tl;dr I want to run devtools::test() on a package and have it skip tests etc. as though it were running on CRAN, but I can't figure out how.
As I understand it, testthat::skip_on_cran() checks for the environment variable NOT_CRAN, which should be…
I am looking for best practice help with the brilliant testthat. Where is the best place to put your library(xyzpackage) calls to use all the package functionality?
I first have been setting up a runtest.R setting up paths and packages.
I then run…
What's the best way to handle calls that generate a warning but then also return a value?
e.g.
> require(testthat)
> expect_warning(log(-1))
> expect_equal(log(-1), NaN)
Warning message:
In log(-1) : NaNs produced
I want to write the test such that…
I am building a package which works with data.table and which should be tested using package testthat.
While the code works fine when calling from the command line, I run into issues when calling from a test case. It seems that the [] function from…
I am using testthat to write unit tests for my R packages. I have seen a few package authors (like those from Rcpp and ggplot2) distributing their unit tests with the binary files.
However, when I build my packages with RStudio (0.98.1102) and…
I have built a package with unit tests for most of the functions. The package has a standard structure:
package:
- R/
- file1.R
- file2.R
- ...
- tests/
- testthat/
- tests_for_file1.R
- tests_for_file2.R
- ...
…
I'm looking to unit test a function that produces a connection. It outputs a message that contains the connection details during execution.
I want to test the following:
The message appears as expected (expect_message(fn(),"blah"))
There is no…
I want to test that a function generates multiple warnings (4 or more), when the order of the warnings can vary. My best attempt to do this is based on look-ahead RegExp matching. Simplifying to just 2 warnings, I know my RegExp work on a single…