Testthat 0.8
testthat 0.8 comes with a new recommended structure for storing your tests. To
better meet CRAN recommended practices, testthat now recommend that you to put
your tests in tests/testthat
, instead of inst/tests
(this makes it
possible for users to choose whether or not to install tests). With this
new structure, you'll need to use test_check()
instead of test_packages()
in the test file (usually tests/testthat.R
) that runs all testthat unit
tests.
The other big improvement to usability comes from @kforner, who contributed
code to allow the default results (i.e. those produced by SummaryReporter
)
to include source references so you can see exactly where failures occured.
New reporters
MultiReporter
, which combines several reporters into one.
(Thanks to @kforner)ListReporter
, which captures all test results with their file,
context, test and elapsed time.test_dir
,test_file
,test_package
and
test_check
now use theListReporter
to invisibly return a summary of
the tests as a data frame. (Thanks to @kforner)TeamCityReporter
to produce output compatible with the TeamCity
continuous integration environment. (Thanks to @windelinckx)SilentReporter
so thattestthat
can test calls totest_that
.
(Thanks to @craigcitro, #83)
New expectations
expect_null()
andis_null
to check if an object is NULL (#78)expect_named()
andhas_names()
to check the names of a vector (#79)expect_more_than()
,is_more_than()
,expect_less_than()
,
is_less_than()
to check values above or below a threshold.
(#77, thanks to @jknowles)
Minor improvements and bug fixes
expect_that()
(and thus allexpect_*
functions) now invisibly return
the expectation result, and stops if info or label arguments have
length > 1 (thanks to @kforner)- fixed two bugs with source_dir(): it did not look for the source scripts
at the right place, and it did not use itschdir
argument. - When using
expect_equal()
to compare strings, the default output for
failure provides a lot more information, which should hopefully help make
finding string mismatches easier. SummaryReporter
has amax_reports
option to limit the number of detailed
failure reports to show. (Thanks to @crowding)- Tracebacks will now also contain information about where the functions came
from (where that information is available). matches
andexpect_match
now pass additional arguments on togrepl
so
that you can usefixed = TRUE
,perl = TRUE
orignore.case = TRUE
to
control details of the match.expect_match
now correctly fails to match
NULL. (#100)expect_output
,expect_message
,expect_warning
andexpect_error
also pass ... on togrepl
, so that you can usefixed = TRUE
,
perl = TRUE
orignore.case = TRUE
- Removed
stringr
andevaluate
dependencies. - The
not()
function makes it possible to negate tests. For example,
expect_that(f(), not(throws_error()))
asserts thatf()
does not
throw an error. - Make
dir_state
less race-y. (Thanks to @craigcitro, #80) auto_test
now pays attention to its 'reporter' argument (Thanks to @crowding, #81)get_reporter()
,set_reporter()
andwith_reporter()
are now
exported (#102)