You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## About This Project
6
+
7
+
testthat is R's most popular unit testing framework, used by thousands of CRAN packages. It provides functions to make testing R code as fun and addictive as possible, with clear expectations, visual progress indicators, and seamless integration with R package development workflows.
8
+
9
+
## Key Development Commands
10
+
11
+
General advice:
12
+
* When running R from the console, always run it with `--quiet --vanilla`
13
+
* Always run `air format .` after generating code
14
+
15
+
### Development tools
16
+
17
+
-`devtools::test()` - Run all tests
18
+
-`devtools::test_file("tests/testthat/test-filename.R")` - Run tests in a specific file
19
+
- DO NOT USE `devtools::test_active_file()`
20
+
-`devtools::load_all()` - Load package for development
21
+
-`devtools::check()` - Run R CMD check
22
+
-`devtools::install()` - Install package locally
23
+
24
+
### Documentation
25
+
26
+
- Always run `devtools::document()` after changing any roxygen2 docs.
-`Config/testthat/start-first` - Tests to run first in parallel mode
78
+
79
+
### C++ Testing Infrastructure
80
+
81
+
testthat provides C++ testing capabilities via Catch framework:
82
+
- Headers in `inst/include/testthat/`
83
+
- Test runner infrastructure in `src/test-runner.cpp`
84
+
- Integration with R's testing system
85
+
86
+
### Snapshot Testing Workflow
87
+
88
+
- Snapshots stored in `tests/testthat/_snaps/`
89
+
- Different snapshot types: values, files, output
90
+
- Version-specific snapshots for different R versions
91
+
- Use `testthat::snapshot_accept()` to update snapshots
92
+
93
+
This codebase prioritizes backward compatibility, comprehensive testing, and clear, descriptive error messages to help R developers write better tests.
Copy file name to clipboardExpand all lines: NEWS.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,41 @@
1
1
# testthat (development version)
2
2
3
+
*`test_dir()`, `test_file()`, `test_package()`, `test_check()`, `test_local()`, `source_file()` gain a `shuffle` argument uses `sample()` to randomly reorder the top-level expressions in each test file (#1942). This random reordering surfaces dependencies between tests and code outside of any test, as well as dependencies between tests. This helps you find and eliminate unintentional dependencies.
4
+
*`snapshot_accept(test)` now works when the test file name contains `.` (#1669).
5
+
*`local_mock()` and `with_mock()` have been deprecated because they are no longer permitted in R 4.5.
6
+
*`snapshot_review()` now passes `...` on to `shiny::runApp()` (#1928).
7
+
*`expect_named()` now gives more informative errors (#2091).
8
+
*`expect_*()` functions consistently and rigorously check their inputs (#1754).
9
+
*`test_that()` no longer warns about the absence of `{}` since it no longer seems to be necessary.
10
+
*`test_that()`, `describe()`, and `it()` can now be arbitrarily nested. Each component will skip only if it and its subtests don't contain any expectations. The interactive stop reporter has been fixed so it doesn't duplicate failures. (#2063, #2188).
11
+
* Test filtering now works with `it()`, and the `desc` argument can take a character vector in order to recursively filter subtests (i.e. `it()` nested inside of `describe()`) (#2118).
12
+
* New `snapshot_reject()` rejects all modified snapshots by deleting the `.new` variants (#1923).
13
+
* New `SlowReporter` makes it easier to find the slowest tests in your package. The easiest way to run it is with `devtools::test(reporter = "slow")` (#1466).
14
+
* Power `expect_mapequal()` with `waldo::compare(list_as_map = TRUE)` (#1521).
15
+
* On CRAN, `test_that()` now automatically skips if a package is not installed (#1585). Practically, this means that you no longer need to check that suggested packages are installed. (We don't do this in the tidyverse because we think it has limited payoff, but other styles advise differently.)
16
+
*`expect_snapshot()` no longer skips on CRAN, as that skips the rest of the test. Instead it just returns, neither succeeding nor failing (#1585).
17
+
* Interrupting a test now prints the test name. This makes it easier to tell where a very slow test might be hanging (#1464)
18
+
* Parallel testthat now does not ignore test files with syntax errors (#1360).
19
+
*`expect_lt()`, `expect_gt()`, and friends have a refined display that is more likely to display the correct number of digits and shows you the actual values compared.
20
+
*`describe()`, `it()`, and `test_that()` now have a shared stack of descriptions so that if you nest any inside of each other, any resulting failures will show you the full path.
21
+
*`describe()` now correctly scopes `skip()` (#2007).
22
+
*`ParallelProgressReporter` now respect `max_failures` (#1162).
23
+
* The last snapshot is no longer lost if the snapshot file is missing the final newline (#2092). It's easy to accidentally remove this because there are two trailing new lines in snapshot files and many editors will automatically remove if you touch the file.
24
+
* New `expect_r6_class()` (#2030).
25
+
*`expect_*()` functions consistently and rigorously check their inputs (#1754).
26
+
*`JunitReporter()` no longer fails with `"no applicable method for xml_add_child"` for warnings outside of tests (#1913). Additionally, warnings now save their backtraces.
27
+
*`JunitReporter()` strips ANSI escapes in more placese (#1852, #2032).
28
+
*`try_again()` is now publicised. The first argument is now the number of retries, not tries (#2050).
29
+
*`vignette("custom-expectations)` has been overhauled to make it much clearer how to create high-quality expectations (#2113, #2132, #2072).
30
+
*`expect_snapshot()` and friends will now fail when creating a new snapshot on CI. This is usually a signal that you've forgotten to run it locally before committing (#1461).
31
+
*`expect_snapshot_value()` can now handle expressions that generate `-` (#1678) or zero length atomic vectors (#2042).
32
+
*`expect_matches()` failures should be a little easier to read (#2135, #2181).
33
+
* New `local_on_cran(TRUE)` allows you to simulate how your tests will run on CRAN (#2112).
34
+
*`expect_no_*()` now executes the entire code block, rather than stopping at the first message or warning (#1991).
35
+
*`expect_no_failures()` and `expect_no_successes()` are now deprecated as `expect_success()` now test for no failures and `expect_failure()` tests for no successes (#)
36
+
* New `pass()` function to use in place of `succeed()` (#2113).
37
+
*`expectation()` is now a combination of `new_expectation()` and `exp_signal()` (#2125).
38
+
*`is_null()`/`matches()` deprecated in 2.0.0 (2017-12-19) and `is_true()`/`is_false()` deprecated in 2.1.0 (2019-04-23) have been removed (#2109).
3
39
*`local_edition()` now gives a useful error for bad values (#1547).
4
40
* testthat now requires R 4.1.
5
41
*`expect_s4_class()` now supports unquoting (@stibu81, #2064).
@@ -9,6 +45,7 @@
9
45
*`skip_on_os()` gains an option `"emscripten"` of the `os` argument to skip tests on Emscripten (@eitsupi, #2103).
10
46
* New expectation, `expect_shape()`, for testing the shape (i.e., the `length()`, `nrow()`, `ncol()`, or `dim()`), all in one place (#1423, @michaelchirico).
11
47
*`expect_snapshot_file(name=)` must have a unique file path. If a snapshot file attempts to be saved with a duplicate `name`, an error will be thrown. (#1592)
48
+
* New expectation, `expect_shape()`, for testing the shape (i.e., the `nrow()`, `ncol()`, or `dim()`), all in one place (#1423, @michaelchirico).
0 commit comments