testthat 2.1.0
New expectations
-
New
expect_visible()
andexpect_invisible()
make it easier to check if
a function call returns its result visibly or invisibly (#719). -
New
expect_mapequal(x, y)
checks thatx
andy
have 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). -
New
expect_vector()
is a wrapper aroundvctrs::vec_assert()
making it
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
object
orexpected
arguments (#743). -
expect_equal()
now correctly compares infinite values (#789). -
In
expect_equal_to_reference()
, the default value forupdate
is
nowFALSE
(@brodieG, #683). -
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 theclass
argument. 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). -
expect_identical()
gains a...
argument to pass additional arguments
down toidentical()
(#714). -
expect_lt()
,expect_lte()
,expect_gt()
expect_gte()
now handleInf
andNA
arguments appropriately (#732), and no longer require the inputs
to be numeric. -
expect_output()
gains awidth
argument, allowing you to control the
output width. This does not inherit fromgetOption("width")
, ensuring
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 thansort()
. It also warns if the inputs
are named, as this suggests that your mental model of howexpect_setequal()
works is wrong (#750). -
is_true()
andis_false()
have been deprecated because they conflict
with other functions in the tidyverse.
Reporters
-
Reporter documentation has been considerably improved (#657).
-
CheckReporter
, used by R CMD check, now includes a count of warnings. -
JUnitReporter
no longer replaces.
in class names (#753), and
creates ouput that should be more compatible with Jenkins (#806, @comicfans). -
ListReporter
now 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 ofcontext()
and instead encourage you to delete it,
allowing the context to be autogenerated from the file name.This also eliminates the error that occured if tests can before the
firstcontext()
(#700, #705). -
Gains a
update_interval
parameter to control how often updates are
printed (default 0.1 s). This prevents large printing overhead
for very fast tests. (#701, @jimhester) -
Uses a 3 character wide column to display test successes, so up to
999 successful tests can be displayed without changing the alignment
(#712).
-
-
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).
Skips
-
skip_if_offline()
skips tests if an internet connection is not available
(#685). -
skip_on_ci()
skips tests on continuous integration systems
(@mbjoseph, #825) by looking for aCI
env var..
Other new features
-
New
testthat_examples()
andtestthat_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. -
New
local_mock()
which allows you to mock a function without having to
add an additional layer of indentation as withwith_mock()
(#856).
Other minor improvements and bug fixes
-
auto_test_package()
works better with recent devtools and also watches
src/
for changes (#809). -
expect_s3_class()
now works with unquoting (@jalsalam, #771). -
expectation
objects now contain the failure message, even when successful
(#836) -
devtools::test()
no longer fails if run multiple times within the same R
session for a package containing Catch tests.
(devtools #1832) -
New
testing_package()
retrieves the name of the package currently being
tested (#699). -
run_testthat_tests
C entrypoint is registered more robustly. -
skip()
now always produces amessage
of length 1, as expected elsewhere
in testthat (#791). -
Warnings are passed through even when
options(warn = 2)
is set
(@yutannihilation, #721).