testthat Questions

5

Solved

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 easi...
Ricardaricardama asked 25/2, 2014 at 2:15

1

I have a package with a suggested dependency enabling optional behaviour. Following the best practice, I added this dependency in my "Suggests" and check if it's installed with requireNam...
Geoid asked 20/10, 2020 at 4:27

2

Solved

In order to develop a package, I am using testthat. I want to test if my functions send proper messages and warnings. I want to test the results of functions at the same time. This is how I am tryi...
Cheeseparing asked 9/3, 2021 at 13:36

1

I'm using GitHub Actions to do the R CMD Check (see https://github.com/r-lib/actions). I would like to use snapshot_file in testthat script of the sort: save_png <- function(code, width = 1000, ...
Saffier asked 9/11, 2020 at 21:50

2

Solved

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:...
Recitativo asked 2/1, 2014 at 15:10

2

Solved

I've deprecated several functions in my R package by including a .Deprecated("new_function_name") line at the start of the function. I had full unit test coverage for those deprecated functions. No...
Koball asked 22/3, 2017 at 12:49

2

Solved

In my understanding, anything put inside test_that() should be compartmentalized, meaning that if I load a package in test_that(), its functions and methods shouldn't be available in other test_tha...
Rutan asked 23/3, 2023 at 12:26

4

Solved

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 fu...
Tedie asked 18/7, 2014 at 10:54

0

R's testthat package has a number of functions for running tests: https://testthat.r-lib.org/reference/index.html#run-tests. However, the most coarse level you can filter tests seems to be at a fil...
Signore asked 16/12, 2022 at 1:58

2

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 f...
Pellet asked 11/4, 2016 at 11:18

1

Solved

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 ...
Kanazawa asked 13/7, 2021 at 20:39

0

Since callr::r and callr::r_bg launch a background process in a clean environment, they do not fit neatly into unit test paradigms. An R unit test, run via testthat, loads the current development v...
Aimeeaimil asked 26/7, 2022 at 17:1

2

I am trying to mock the output of a gh API request: httptest2::with_mock_dir("gh", { test_that("api works", { gh::gh("GET /repos/r-lib/gh") }) }) I am trying to se...
Devoice asked 3/7, 2022 at 23:48

2

Solved

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 ...
Apoenzyme asked 13/7, 2015 at 10:11

4

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 scr...
Sheikdom asked 1/9, 2015 at 10:2

1

This test in my package works fine with devtools::test(). Also the online Travis build is going well. test_that("Package style", { lintr::expect_lint_free() }) However, with devtools::c...
Trunnion asked 23/6, 2020 at 17:52

7

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, ho...
Therrien asked 25/1, 2017 at 8:15

3

Solved

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 b...
Stroh asked 4/10, 2015 at 9:15

1

Solved

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 intere...
Buckjumper asked 15/12, 2016 at 13:45

1

Solved

I would like to run the package-internal tests with testthat::test_package('httr') on a specific version of a package. Is there a way to install a R package (e.g. from CRAN) with a specific version...
Lamonica asked 23/8, 2021 at 10:6

1

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_fra...
Syllabi asked 10/6, 2016 at 0:42

2

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 ...
Condenser asked 20/9, 2019 at 10:49

1

Solved

I am trying to develop unit tests for my shiny app, which was made using golem framework and shiny v1.5.0. Golem comes with a recommended test file, which covers very basic UI testing. I am, howeve...
Hord asked 16/10, 2020 at 14:37

2

Solved

I am looking for the easiest way to mock response of rest API within testthat framework. Example of usage would be similar to this: with_mock_api( request, response, { call_to_function_with...
Nubilous asked 6/10, 2019 at 20:39

1

Solved

(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 browse...
Veterinary asked 10/8, 2020 at 8:32

© 2022 - 2024 — McMap. All rights reserved.