Run a single test function in R's testthat
Asked Answered
S

0

8

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 file level, since there is a test_file() function that doesn't have any filtering arguments, and test_dir() has a filter argument but it is only used to filter by filename.

However I frequently want to only run a single test, because it's new, or because I know it's relevant to a change I just made.

Is there a way, in the R console or in RStudio to run a single testthat test? If not, is there some other recommended solution to this problem such as putting each test in it's own file (this seems pretty painful though)?

Signore answered 16/12, 2022 at 1:58 Comment(1)
You should put slow tests in their own file. Fast tests can be grouped into the same file. You may not care about the results of all of them, but if they are fast, why worry about it?Tilghman

© 2022 - 2024 — McMap. All rights reserved.