I am using Hadley's testthat-based approach for automated testing of my package.
With this approach, what is the most suitable place to put test data files that is files only used by the test scripts in tests/testthat), but not by any other…
I have a lot of functions that generate plots, typically with ggplot2. Right now, I'm generating the plot and testing the underlying data. But I'd like to know if there's a reasonable way to test that the plot contains the layers/options I expect it…
I am wondering how to test functions that produce graphics. I have a simple
plotting function img:
img <- function() {
plot(1:10)
}
In my package I like to create a unit test for this function using testthat.
Because plot and its friends in base…
I would like to know if it is possible in R using testthat test framework to set the tolerance for equality.
Currently, if example.R is:
library(testthat)
three_times<-function(x) 3*x
context('Test three_times')
test_that('Three times returns 3…
I'm writing tests for a function that under some conditions will generate warnings. I want to ensure that under the other conditions it does not produce warnings. I don't see an obvious way to easily test that with testthat. I guess I could do…
I am using the testthat package in R and I am trying to test a function
defined in a file example.R. This file contains a call source("../utilities/utilities.R") where utilities.R is a file with functions written by me. However, when I am trying to…
Is it possible to invoke the debugger in RStudio when running testthat tests? I haven't been able to find a setup that allows this (various combinations of "use devtools package functions if available" in the settings, hitting the "Test Package"…
What is the correct usage of expect_error() in testthat package? I've tried to adapt example from help, but this fails when I use brackets in error message.
library(testthat)
# Works
tmp1 <- function() stop("Input is not correct")
…
I am writing a R package, and I'm using testthat for unit testing. Many of my unit tests are for testing functions that work on a certain object specific to my package. For these tests I have made a helper function to set up a mock object. I have a…
I have a shiny application which uses like 4 functions. I would like to test these functions but it's not a package. How am i supposed to structure my code ? and execute these tests without devtools ?
Suppose I have test like this:
require(testthat)
context("toy test")
test_that("toy", {
df = my.read.file("test.txt", header=TRUE)
expect_true(myfunc(df) == 3.14)
})
and this test relies on a external file test.txt, where…
There are apparently two ways to integrate testthat with R CMD check. I can't get either to work.
Approach #1: (perhaps deprecated)
According to the devtools wiki:
When developing a package, put your tests in inst/tests and then
create a file…
Is there any way to reproduce the environment which is used by devtools::check?
I have the problem that my tests work with devtools::test() but fail within devtools::check(). My problem is now, how to find the problem. The report of check just…
I am developing an R app and came up with a workaround to integrate testthat in it (it usually requires your project to be a package) by adding a DESCRIPTION file to the project root.
I got this method from a colleague who managed to get it to work…
I am using testthat to check the code in my package. Some of my tests are for basic functionality, such as constructors and getters. Others are for complex functionality that builds on top of the basic functionality. If the basic tests fail, then it…