Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

skip

Skip a test


Description

skip_if() and skip_if_not() allow you to skip tests, immediately concluding a test_that() block without executing any further expectations. This allows you to skip a test without failure, if for some reason it can't be run (e.g. it depends on the feature of a specific operating system, or it requires a specific version of a package).

See vignette("skipping") for more details.

Usage

skip(message)

skip_if_not(condition, message = NULL)

skip_if(condition, message = NULL)

skip_if_not_installed(pkg, minimum_version = NULL)

skip_if_offline(host = "r-project.org")

skip_on_cran()

skip_on_os(os)

skip_on_travis()

skip_on_appveyor()

skip_on_ci()

skip_on_covr()

skip_on_bioc()

skip_if_translated(msgid = "'%s' not found")

Arguments

message

A message describing why the test was skipped.

condition

Boolean condition to check. skip_if_not() will skip if FALSE, skip_if() will skip if TRUE.

pkg

Name of package to check for

minimum_version

Minimum required version for the package

host

A string with a hostname to lookup

os

Character vector of system names. Supported values are "windows", "mac", "linux" and "solaris".

msgid

R message identifier used to check for translation: the default uses a message included in most translation packs. See the complete list in R-base.pot.

Helpers

  • skip_if_not_installed("pkg") skips tests if package "pkg" is not installed or cannot be loaded (using requireNamespace()). Generally, you can assume that suggested packages are installed, and you do not need to check for them specifically, unless they are particularly difficult to install.

  • skip_if_offline() skips if an internet connection is not available (using curl::nslookup()).

  • skip_if_translated("msg") skips tests if the "msg" is translated.

  • skip_on_bioc() skips on Bioconductor (using the BBS_HOME env var).

  • skip_on_cran() skips on CRAN (using the NOT_CRAN env var set by devtools and friends).

  • skip_on_covr() skips when covr is running (using the R_COVR env var).

  • skip_on_ci() skips on continuous integration systems like GitHub Actions, travis, and appveyor (using the CI env var). It supersedes the older skip_on_travis() and skip_on_appveyor() functions.

  • skip_on_os() skips on the specified operating system(s) ("windows", "mac", "linux", or "solaris").

Examples

if (FALSE) skip("No internet connection")

test_that("skip example", {
  expect_equal(1, 1L)    # this expectation runs
  skip('skip')
  expect_equal(1, 2)     # this one skipped
  expect_equal(1, 3)     # this one is also skipped
})

testthat

Unit Testing for R

v3.0.2
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], RStudio [cph, fnd], R Core team [ctb] (Implementation of utils::recover())
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.