Skip to content

Testthat 0.8

Compare
Choose a tag to compare
@hadley hadley released this 21 Feb 19:47

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 the ListReporter 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 that testthat can test calls to test_that.
    (Thanks to @craigcitro, #83)

New expectations

  • expect_null() and is_null to check if an object is NULL (#78)
  • expect_named() and has_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 all expect_* 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 its chdir 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 a max_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 and expect_match now pass additional arguments on to grepl so
    that you can use fixed = TRUE, perl = TRUE or ignore.case = TRUE to
    control details of the match. expect_match now correctly fails to match
    NULL. (#100)
  • expect_output, expect_message, expect_warning and expect_error
    also pass ... on to grepl, so that you can use fixed = TRUE,
    perl = TRUE or ignore.case = TRUE
  • Removed stringr and evaluate dependencies.
  • The not() function makes it possible to negate tests. For example,
    expect_that(f(), not(throws_error())) asserts that f() 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() and with_reporter() are now
    exported (#102)