expect_invisible()make it easier to check if
a function call returns its result visibly or invisibly (#719).
expect_mapequal(x, y)checks that
yhave the same names,
and the same value associated with each name (i.e. they compare the values
of the vector standardising the order of the names) (#863).
expect_vector()is a wrapper around
easy to test against the vctrs definitions of prototype and size (#846).
(Currently requires development version of vctrs.)
Improvements to existing expectations
All expectations give clearer error messages if you forget the
expect_equal()now correctly compares infinite values (#789).
expect_error()now returns the error object as documentated (#724).
It also now warns if you're using a classed expectation and you're
not using the
classargument. This is good practice as it decouples the
error object (which tends to be stable) from its rendering to the user
(which tends to be fragile) (#816).
...argument to pass additional arguments
NAarguments appropriately (#732), and no longer require the inputs
to be numeric.
widthargument, allowing you to control the
output width. This does not inherit from
that tests return the same results regardless of environment (#805).
expect_setequal()now works with more vector types (including lists),
because it uses
%in%, rather than
sort(). It also warns if the inputs
are named, as this suggests that your mental model of how
works is wrong (#750).
is_false()have been deprecated because they conflict
with other functions in the tidyverse.
Reporter documentation has been considerably improved (#657).
CheckReporter, used by R CMD check, now includes a count of warnings.
ListReporternow records number of passed tests and original results in
new columns (#675).
ProgressReporter, the default reporter, now:
Automatically generates a context from the file name. We no longer
recommend the use of
context()and instead encourage you to delete it,
allowing the context to be autogenerated from the file name.
Uses a 3 character wide column to display test successes, so up to
999 successful tests can be displayed without changing the alignment
reporter$end_reporter()is now only called when testing completes
successfully. This ensures that you don't get unnecessary output when the
test fails partway through (#727).
skip_if_offline()skips tests if an internet connection is not available
Other new features
testthat_example()make it easy to access
new test files bundled with the package. These are used in various examples
to make it easier to understand how to use the package.
local_mock()which allows you to mock a function without having to
add an additional layer of indentation as with
Other minor improvements and bug fixes
auto_test_package()works better with recent devtools and also watches
src/for changes (#809).
expectationobjects now contain the failure message, even when successful
devtools::test()no longer fails if run multiple times within the same R
session for a package containing Catch tests.
testing_package()retrieves the name of the package currently being
run_testthat_testsC entrypoint is registered more robustly.
skip()now always produces a
messageof length 1, as expected elsewhere
in testthat (#791).