Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to determine test order in testthat?

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 is expected that the complex tests will fail, so there is no point testing further.

Is it possible to:

  1. Ensure that the basic tests are always done first
  2. Make a test-failure halt the testing process
like image 222
sdgfsdh Avatar asked Oct 04 '15 09:10

sdgfsdh


People also ask

How do I run a Testthat test?

If you're using RStudio, press Cmd/Ctrl + Shift + T (or run devtools::test() if not) to run all the tests in a package.

What is Testthat in R?

'testthat' is a testing framework for R that is easy to learn and use, and integrates with your existing 'workflow'. License MIT + file LICENSE. URL https://testthat.r-lib.org, https://github.com/r-lib/testthat. BugReports https://github.com/r-lib/testthat/issues. Depends R (>= 3.1)

How do you write a unit test in R?

Create a directory called tests and put there one ore more R scripts all starting with test_ as a file name. After this you could just start the unit testing code by calling testthat::test_dir(“tests”) within R and you will see an output similar to that. The output is shown after calling the tests.


1 Answers

To answer your question, I don't think it can be determined other than by having appropriate alphanumeric naming of your test-*.R files.

From testthat source, this is the function which test_package calls, via test_dir, to get the tests:

find_test_scripts <- function(path, filter = NULL, invert = FALSE, ...) {
  files <- dir(path, "^test.*\\.[rR]$", full.names = TRUE)

What is wrong with just letting the complex task fail first, anyway?

like image 97
Jack Wasey Avatar answered Oct 31 '22 06:10

Jack Wasey