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_packageand
test_checknow use theListReporterto invisibly return a summary of
the tests as a data frame. (Thanks to @kforner)TeamCityReporterto produce output compatible with the TeamCity
continuous integration environment. (Thanks to @windelinckx)SilentReporterso thattestthatcan test calls totest_that.
(Thanks to @craigcitro, #83)
New expectations
expect_null()andis_nullto 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 itschdirargument. - 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. SummaryReporterhas amax_reportsoption 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). matchesandexpect_matchnow pass additional arguments on togreplso
that you can usefixed = TRUE,perl = TRUEorignore.case = TRUEto
control details of the match.expect_matchnow correctly fails to match
NULL. (#100)expect_output,expect_message,expect_warningandexpect_error
also pass ... on togrepl, so that you can usefixed = TRUE,
perl = TRUEorignore.case = TRUE- Removed
stringrandevaluatedependencies. - 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_stateless race-y. (Thanks to @craigcitro, #80) auto_testnow pays attention to its 'reporter' argument (Thanks to @crowding, #81)get_reporter(),set_reporter()andwith_reporter()are now
exported (#102)