Questions tagged [testthat]

testthat is a testing tool for R.

testthat is an package for , which is inspired by the family of testing packages and various testing libraries.

Repositories

Other resources

Related tags

366 questions
9
votes
2 answers

Can I automatically generate unit tests for testthat from roxygen2 examples?

I'm working on the PKNCA package for R. While developing the testing code, some of the tests would also be good examples. I want to keep them as both (test and example). Is there a way that I can embed something within the roxygen2 documentation…
Bill Denney
  • 766
  • 1
  • 6
  • 21
9
votes
2 answers

R package tests are not found when running R CMD check

I am using the testthat package to write tests for my R package. I have followed the instructions at http://r-pkgs.had.co.nz/tests.html (I believe). I used devtools::use_testthat() to set up the testing skeleton. I have created a test file in…
Tim Keighley
  • 313
  • 2
  • 8
9
votes
1 answer

Unit tests for code in the /src folder of an R package?

I am contributing to an R package that makes extensive use of C code for computation. We have started writing tests for R functions using the testthat package, placing the tests in inst/tests following instructions here. Is the testthat package…
David LeBauer
  • 31,011
  • 31
  • 115
  • 189
8
votes
2 answers

GitLab CI with r testthat package

Can anyone run testthat tests for a minimal R package using GitLab.com continuous integration tools? My attempt: https://gitlab.com/djchapman/CI_example This is the .gitlab-CI.yml text I am using, image: rocker/rstudio test: script: - R -e…
djchapman
  • 205
  • 1
  • 9
8
votes
2 answers

How to produce jUnit fie with R testthat

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") # --…
Bulat
  • 6,869
  • 1
  • 29
  • 52
8
votes
1 answer

How to set tolerance of expect_equal in testthat when comparing data_frames?

I'm having trouble using testthat's tolerance parameter when I check whether two data_frames are equal. Here's a simple example with two data frames: library(dplyr) library(testthat) d1 = data_frame(a = c(1, 1), b = c(2, 2)) d2 =…
Eric
  • 829
  • 1
  • 8
  • 15
8
votes
1 answer

How to write unit tests for suggested packages?

Packages in R can have different types of dependencies on other packages. Some of these types indicate hard requirements, i.e. Depends, Imports and LinkingTo. However, there is a second category that indicate a softer dependency, i.e. Suggests and…
Andrie
  • 176,377
  • 47
  • 447
  • 496
8
votes
2 answers

R testthat package: How can I see output from message() when using test_file()

I am using the excellent testthat package in R. My issue is that I cannot see any output from the message() function in the code being tested when using test_file. for example, say I have following code in a file called test_message.R f <-…
user2793761
  • 183
  • 1
  • 3
  • 6
7
votes
1 answer

Why does testthat 2.3.2 use a different sort()

(This question is also asked at Github here) After an upgrade of R to 4.0.2 tests fail because it seems, the algorithm of sort in testthat changed. The following shows, that base::sort() and browser() are fine in R 4.0.2 (See this question, why this…
Christoph
  • 6,841
  • 4
  • 37
  • 89
7
votes
2 answers

How can I test for a data frame content?

I have a routine that returns a data frame. I want to check if its values are reasonable. Using testthat I have expect_equal, but I am not sure if it applies to data.frames. I tried to do this but it doesn't…
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
7
votes
1 answer

Test package function that writes to disk

I am trying to write a test for a package function in R. Let's say we have a function that simply writes a string x to disk using writeLines(): exporting_function <- function(x, file) { writeLines(x, con = file) invisible(NULL) } One way of…
clemens
  • 6,653
  • 2
  • 19
  • 31
7
votes
1 answer

Test interaction with users in R package

I am developing an R package and one of the function implements interaction with users through standard input via readline. I now wonder how to test the behavior of this function, preferably with testthat library. It seems test_that function…
Kota Mori
  • 6,510
  • 1
  • 21
  • 25
7
votes
2 answers

How to test an installed package with testthat?

I would like to test an installed package, but this returns an error. library(testthat) test_package("testthat") # Error: No tests found for testthat test_package (source here) returns this error because system.file("tests", package = package) is…
Paul Rougieux
  • 10,289
  • 4
  • 68
  • 110
7
votes
1 answer

How to use R's testthat to unit test individual files?

I'm just now getting into unit testing with R and finding it tough sledding so far. What I'd like to do is go into the R console, type test() and have testthat run tests for all the files in my R package. Here's my environment: sessionInfo() R…
Will Lovett
  • 1,241
  • 3
  • 18
  • 35
7
votes
2 answers

Skip all testthat tests when condition not met

What is the proper way to skip all tests in the test directory of an R package when using testthat/devtools infrastructure? For example, if there is no connection to a database and all the tests rely on that connection, do I need to write a skip in…
Rorschach
  • 31,301
  • 5
  • 78
  • 129
1 2
3
24 25