Skip to content
Choose a tag to compare

testthat 2.1.0

@hadley hadley released this
· 626 commits to master since this release
Choose a tag to compare

New expectations

  • New expect_visible() and expect_invisible() make it easier to check if
    a function call returns its result visibly or invisibly (#719).

  • New expect_mapequal(x, y) checks that x and y 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 around vctrs::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
    or expected arguments (#743).

  • expect_equal() now correctly compares infinite values (#789).

  • In expect_equal_to_reference(), the default value for update is
    now FALSE (@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 the class 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 to identical() (#714).

  • expect_lt(), expect_lte(), expect_gt() expect_gte() now handle Inf
    and NA arguments appropriately (#732), and no longer require the inputs
    to be numeric.

  • expect_output() gains a width argument, allowing you to control the
    output width. This does not inherit from getOption("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 than sort(). It also warns if the inputs
    are named, as this suggests that your mental model of how expect_setequal()
    works is wrong (#750).

  • is_true() and 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.

  • 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 of context() 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
      first context() (#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

  • 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

  • skip_on_ci() skips tests on continuous integration systems
    (@mbjoseph, #825) by looking for a CI env var..

Other new features

  • New testthat_examples() and 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.

  • New local_mock() which allows you to mock a function without having to
    add an additional layer of indentation as with with_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

  • 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 a message of length 1, as expected elsewhere
    in testthat (#791).

  • Warnings are passed through even when options(warn = 2) is set
    (@yutannihilation, #721).