From c923808a07ca4bb7148559d5958aa924938d40d9 Mon Sep 17 00:00:00 2001 From: hadley Date: Wed, 29 Nov 2023 14:07:18 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20r-lib/te?= =?UTF-8?q?stthat@11b62e0f122ce5eea0c8a0aed1922353406d6b84=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev/pkgdown.yml | 2 +- dev/reference/compare.html | 20 ++++++++++---------- dev/reference/expect_snapshot_file.html | 2 +- dev/search.json | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index 673c21a6b..168a46697 100644 --- a/dev/pkgdown.yml +++ b/dev/pkgdown.yml @@ -9,7 +9,7 @@ articles: special-files: special-files.html test-fixtures: test-fixtures.html third-edition: third-edition.html -last_built: 2023-11-28T13:13Z +last_built: 2023-11-29T14:06Z urls: reference: https://testthat.r-lib.org/reference article: https://testthat.r-lib.org/articles diff --git a/dev/reference/compare.html b/dev/reference/compare.html index 0ff8d1b3c..64bf8f162 100644 --- a/dev/reference/compare.html +++ b/dev/reference/compare.html @@ -224,16 +224,16 @@

Examplesx <- y <- runif(100) y[sample(100, 10)] <- 5 compare(x, y) -#> 10/100 mismatches (average diff: 4.31) -#> [18] 0.839 - 5 == -4.16 -#> [24] 0.348 - 5 == -4.65 -#> [27] 0.757 - 5 == -4.24 -#> [29] 0.860 - 5 == -4.14 -#> [35] 0.432 - 5 == -4.57 -#> [47] 0.917 - 5 == -4.08 -#> [61] 0.537 - 5 == -4.46 -#> [63] 0.508 - 5 == -4.49 -#> [69] 0.900 - 5 == -4.10 +#> 10/100 mismatches (average diff: 4.42) +#> [13] 0.643 - 5 == -4.36 +#> [14] 0.661 - 5 == -4.34 +#> [18] 0.814 - 5 == -4.19 +#> [25] 0.607 - 5 == -4.39 +#> [47] 0.999 - 5 == -4.00 +#> [54] 0.806 - 5 == -4.19 +#> [64] 0.968 - 5 == -4.03 +#> [79] 0.039 - 5 == -4.96 +#> [83] 0.144 - 5 == -4.86 #> ... x <- y <- 1:10 diff --git a/dev/reference/expect_snapshot_file.html b/dev/reference/expect_snapshot_file.html index 209dc25e0..76a7648f9 100644 --- a/dev/reference/expect_snapshot_file.html +++ b/dev/reference/expect_snapshot_file.html @@ -206,7 +206,7 @@

Examples} path <- save_png(plot(1:5)) path -#> [1] "/tmp/RtmphshBqb/file19fb57bb5eb4.png" +#> [1] "/tmp/RtmpmdYlvE/file1939d968908.png" if (FALSE) { expect_snapshot_file(save_png(hist(mtcars$mpg)), "plot.png") diff --git a/dev/search.json b/dev/search.json index e3107097a..62786d8ea 100644 --- a/dev/search.json +++ b/dev/search.json @@ -1 +1 @@ -[{"path":[]},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://testthat.r-lib.org/dev/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 testthat authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"expectation-basics","dir":"Articles","previous_headings":"","what":"Expectation basics","title":"Custom expectations","text":"three main parts writing expectation, illustrated expect_length():","code":"expect_length <- function(object, n) { # 1. Capture object and label act <- quasi_label(rlang::enquo(object), arg = \"object\") # 2. Call expect() act$n <- length(act$val) expect( act$n == n, sprintf(\"%s has length %i, not length %i.\", act$lab, act$n, n) ) # 3. Invisibly return the value invisible(act$val) }"},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"quasi-labelling","dir":"Articles","previous_headings":"Expectation basics","what":"Quasi-labelling","title":"Custom expectations","text":"first step expectation capture actual object, generate label use failure occur. testthat expectations support quasiquotation can unquote variables. makes easier generate good labels expectation called function within loop. convention, first argument every expect_ function called object, capture ’s value (val) label (lab) act <- quasi_label(enquo(object)), act short actual.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"verify-the-expectation","dir":"Articles","previous_headings":"Expectation basics","what":"Verify the expectation","title":"Custom expectations","text":"Next, verify expectation. often involves little computation (just figuring length), typically store results back act object. Next call expect(). two arguments: ok: expectation successful? usually easy write failure_message: informative error message reported user can diagnose problem. often hard write! historical reasons, built-expectations generate sprintf(), today ’d recommend using glue package","code":""},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"invisibly-return-the-input","dir":"Articles","previous_headings":"Expectation basics","what":"Invisibly return the input","title":"Custom expectations","text":"Expectation functions called primarily side-effects (triggering failure), invisibly return input, act$val. allows expectations chained:","code":"mtcars %>% expect_type(\"list\") %>% expect_s3_class(\"data.frame\") %>% expect_length(11)"},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"succeed-and-fail","dir":"Articles","previous_headings":"","what":"succeed() and fail()","title":"Custom expectations","text":"expectations complex logic governing success failure occurs, can use succeed() fail(). simple wrappers around expect() allow write code looks like :","code":"expect_length <- function(object, n) { act <- quasi_label(rlang::enquo(object), arg = \"object\") act$n <- length(act$val) if (act$n == n) { succeed() return(invisible(act$val)) } message <- sprintf(\"%s has length %i, not length %i.\", act$lab, act$n, n) fail(message) }"},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"setup","dir":"Articles","previous_headings":"","what":"Setup","title":"Running tests in parallel","text":"enable parallel testing, must first using 3rd edition1. add following line DESCRIPTION: default, testthat use getOption(\"Ncpus\", 2) cores. increase value development machine recommend setting TESTTHAT_CPUS .Renviron. easiest way call usethis::edit_r_environ() add something like following: Tests run alphabetical order default, can often improve performance starting slowest tests first. Specify tests supplying comma separated list glob patterns2 Config/testthat/start-first field DESCRIPTION, e.g.:","code":"Config/testthat/parallel: true TESTTHAT_CPUS=4 Config/testthat/start-first: watcher, parallel*"},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"basic-operation","dir":"Articles","previous_headings":"","what":"Basic operation","title":"Running tests in parallel","text":"worker begins loading testthat package tested. runs setup files (existing setup files ’ll need make sure work executed parallel). testthat runs test files parallel. worker pool initialized, testthat starts sending test files workers, default alphabetical order: soon subprocess finished, receives another file, files done. means state persisted across test files: options reset, loaded packages unloaded, global environment cleared, etc. responsible making sure file leaves world finds .","code":""},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"common-problems","dir":"Articles","previous_headings":"","what":"Common problems","title":"Running tests in parallel","text":"tests fail stochastically (.e. sometimes work sometimes fail) may accidentally introduced dependency test files. sort dependency hard track due random nature, ’ll need check tests make sure ’re accidentally changing global state. set_state_inspector() make easier. use packaged scope test fixtures, ’ll need review make sure work parallel. example, previously creating temporary database test directory, ’d need instead create session temporary directory process gets independent version.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"performance","dir":"Articles","previous_headings":"","what":"Performance","title":"Running tests in parallel","text":"overhead associated running tests parallel: Startup cost linear number subprocesses, need create loop. 50ms laptop. subprocess needs load testthat tested package, happens parallel, much . Clean time linear number subprocesses, 80ms per subprocess laptop. seems sending message (.e. passing failing expectation) 2ms currently. total cost includes sending message, receiving , replying non-parallel reporter. overhead generally means many test files take short amount time, ’re unlikely see huge benefit using parallel tests. example, testthat takes 10s run tests serial, 8s run tests parallel.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"default-reporters","dir":"Articles","previous_headings":"Reporters","what":"Default reporters","title":"Running tests in parallel","text":"See default_reporter() testthat selects default reporter devtools::test() testthat::test_local(). short, testthat selects ProgressReporter non-parallel ParallelProgressReporter parallel tests default. (testthat test functions, like test_check(), test_file() , etc. select different reporters default.)","code":""},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"parallel-support","dir":"Articles","previous_headings":"Reporters","what":"Parallel support","title":"Running tests in parallel","text":"reporters support parallel tests. reporter passed devtools::test(), testthat::test_dir(), etc. directly, support parallel tests, testthat runs test files sequentially. Currently following reporters don’t support parallel tests: DebugReporter, currently possible debug subprocesses. JunitReporter, reporter records timing information test block, currently available reporters support multiple active test files. (See “Writing parallel reporters” .) LocationReporter testthat currently include location information successful tests running parallel, minimize messaging processes. StopReporter, reporter testthat uses interactive expect_that() calls. built-reporters support parallel tests, subtle differences: Reporters stop certain number failures can stop end test file. Reporters report information file , unless support parallel updates. E.g. ProgressReporter update display test file complete. standard output standard error, .e. print(), cat(), message(), etc. output test files lost currently. want use cat() message() print-debugging test cases, best temporarily run tests sequentially, changing Config entry DESCRIPTION selecting non-parallel reporter, e.g. CheckReporter:","code":"devtools::test(filter = \"badtest\", reporter = \"check\")"},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"writing-parallel-reporters","dir":"Articles","previous_headings":"Reporters","what":"Writing parallel reporters","title":"Running tests in parallel","text":"support parallel tests, reporter must able function test files run subprocess. example DebugReporter support parallel tests, requires direct interaction frames subprocess. running parallel, testthat provide location information (source references) test successes. support parallel tests, reporter must set self$capabilities$parallel_support TRUE initialize() method: running parallel, testthat runs reporter main process, relays information reporter test code transparently. (Currently reporter even know tests running parallel.) reporter support parallel updates (see ), testthat internally caches calls reporter methods subprocesses, test file complete. reporters prepared running multiple test files concurrently. test file complete, testthat calls reporter’s $start_file() method, relays $start_test() , $end_test(), $add_result(), etc. calls order came subprocess, calls $end_file() .","code":"... initialize = function(...) { super$initialize(...) self$capabilities$parallel_support <- TRUE ... } ..."},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"parallel-updates","dir":"Articles","previous_headings":"Reporters","what":"Parallel updates","title":"Running tests in parallel","text":"ParallelProgressReporter supports parallel updates. means message subprocess comes , reporter updated immediately. work, reporter must able handle multiple test files concurrently. reporter declares parallel update support setting self$capabilities$parallel_updates TRUE: reporters, testthat cache messages subprocesses. Instead, message comes : calls $start_file() method, letting reporter know file following calls apply . means reporter can receive multiple $start_file() calls file. relays message subprocess, calling appropriate $start_test() , $add_result(), etc. method. testthat also calls new $update() method reporter regularly, even receive messages subprocess. (Currently aims every 100ms, guarantees.) $update() method may implement spinner let user know tests running.","code":"... initialize = function(...) { super$initialize(...) self$capabilities$parallel_support <- TRUE self$capabilities$parallel_updates <- TRUE ... } ..."},{"path":"https://testthat.r-lib.org/dev/articles/skipping.html","id":"basics","dir":"Articles","previous_headings":"","what":"Basics","title":"Skipping tests","text":"testthat comes variety helpers common situations: skip_on_cran() skips tests CRAN. useful slow tests tests occasionally fail reasons outside control. skip_on_os() allows skip tests specific operating system. Generally, strive avoid much possible (code works platforms), sometimes ’s just possible. skip_on_ci() skips tests continuous integration platforms (e.g. GitHub Actions, Travis, Appveyor). can also easily implement using either skip_if() skip_if_not(), take expression yield single TRUE FALSE. reporters show tests skipped. testthat 3.0.0, ProgressReporter (used interactively) CheckReporter (used inside R CMD check) also display summary skips across tests. looks something like : keep eye developing interactively make sure ’re accidentally skipping wrong things.","code":"── Skipped tests ─────────────────────────────────────────────────────── ● No token (3) ● On CRAN (1)"},{"path":"https://testthat.r-lib.org/dev/articles/skipping.html","id":"helpers","dir":"Articles","previous_headings":"","what":"Helpers","title":"Skipping tests","text":"find using skip_if()/skip_if_not() expression across multiple tests, ’s good idea create helper function. function start skip_ live test/helper-{something}.R file:","code":"skip_if_dangerous <- function() { if (!identical(Sys.getenv(\"DANGER\"), \"\")) { skip(\"Not run in dangerous environments.\") } else { invisible() } }"},{"path":"https://testthat.r-lib.org/dev/articles/skipping.html","id":"embedding-skip-in-package-functions","dir":"Articles","previous_headings":"","what":"Embedding skip() in package functions","title":"Skipping tests","text":"Another useful technique can sometimes useful build skip() directly package function. example take look pkgdown:::convert_markdown_to_html(), absolutely, positively work Pandoc tool unavailable: Pandoc available convert_markdown_to_html() executes, throws error unless appears part test run, case test skipped. alternative implementing custom skipper, e.g. skip_if_no_pandoc(), inserting many pkgdown’s tests. don’t want pkgdown runtime dependency testthat, pkgdown includes copy testthat::is_testing(): might look like code appears still runtime dependency testthat, call testthat::skip(). testthat::skip() executed test run, implies testthat installed. mixed feelings approach. one hand, feels elegant concise, absolutely guarantees ’ll never miss needed skip one tests. hand, mixes code tests unusual way, ’re focused tests, ’s easy miss fact package function contains skip().","code":"convert_markdown_to_html <- function(in_path, out_path, ...) { if (rmarkdown::pandoc_available(\"2.0\")) { from <- \"markdown+gfm_auto_identifiers-citations+emoji+autolink_bare_uris\" } else if (rmarkdown::pandoc_available(\"1.12.3\")) { from <- \"markdown_github-hard_line_breaks+tex_math_dollars+tex_math_single_backslash+header_attributes\" } else { if (is_testing()) { testthat::skip(\"Pandoc not available\") } else { abort(\"Pandoc not available\") } } ... } is_testing <- function() { identical(Sys.getenv(\"TESTTHAT\"), \"true\") }"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"basic-workflow","dir":"Articles","previous_headings":"","what":"Basic workflow","title":"Snapshot tests","text":"’ll illustrate basic workflow simple function generates HTML heading. can optionally include id attribute, allows construct link directly heading. Testing simple function relatively painful. write test carefully escape newlines quotes. re-read test future, escaping makes hard tell exactly ’s supposed return. great place use snapshot testing. make two changes code: use expect_snapshot() instead expect_equal() wrap call cat() (avoid [1] output, like first interactive example). yields following test: run test first time, automatically generates reference output, prints , can visually confirm ’s correct. output automatically saved _snaps/{name}.md. name snapshot matches test file name — e.g. test test-pizza.R snapshot saved test/testthat/_snaps/pizza.md. file name suggests, markdown file, ’ll explain shortly. run test , ’ll succeed: change underlying code, say tweak indenting, test fail: deliberate change, can follow advice message update snapshots file running snapshot_accept(\"pizza\"); otherwise can fix bug tests pass . (can also accept snapshot files snapshot_accept()).","code":"bullets <- function(text, id = NULL) { paste0( \"\\n\", paste0(\"
  • \", text, \"<\/li>\\n\", collapse = \"\"), \"<\/ul>\\n\" ) } cat(bullets(\"a\", id = \"x\")) #>
      #>
    • a<\/li> #> <\/ul> test_that(\"bullets\", { expect_equal(bullets(\"a\"), \"
        \\n
      • a<\/li>\\n<\/ul>\\n\") expect_equal(bullets(\"a\", id = \"x\"), \"
          \\n
        • a<\/li>\\n<\/ul>\\n\") }) #> Test passed test_that(\"bullets\", { expect_snapshot(cat(bullets(\"a\"))) expect_snapshot(cat(bullets(\"a\", \"b\"))) }) #> -- Warning: bullets ------------------------------------------------------------ #> Adding new snapshot: #> Code #> cat(bullets(\"a\")) #> Output #>
            #>
          • a<\/li> #> <\/ul> #> #> -- Warning: bullets ------------------------------------------------------------ #> Adding new snapshot: #> Code #> cat(bullets(\"a\", \"b\")) #> Output #>
              #>
            • a<\/li> #> <\/ul> test_that(\"bullets\", { expect_snapshot(cat(bullets(\"a\"))) expect_snapshot(cat(bullets(\"a\", \"b\"))) }) #> Test passed bullets <- function(text, id = NULL) { paste0( \"\\n\", paste0(\"
            • \", text, \"<\/li>\\n\", collapse = \"\"), \"<\/ul>\\n\" ) } test_that(\"bullets\", { expect_snapshot(cat(bullets(\"a\"))) expect_snapshot(cat(bullets(\"a\", \"b\"))) }) #> -- Failure: bullets ------------------------------------------------------------ #> Snapshot of code has changed: #> old | new #> [2] cat(bullets(\"a\")) | cat(bullets(\"a\")) [2] #> [3] Output | Output [3] #> [4]
                |
                  [4] #> [5]
                • a<\/li> -
                • a<\/li> [5] #> [6] <\/ul> | <\/ul> [6] #> #> * Run `testthat::snapshot_accept('snapshotting.Rmd')` to accept the change. #> * Run `testthat::snapshot_review('snapshotting.Rmd')` to interactively review the change. #> #> -- Failure: bullets ------------------------------------------------------------ #> Snapshot of code has changed: #> old | new #> [2] cat(bullets(\"a\", \"b\")) | cat(bullets(\"a\", \"b\")) [2] #> [3] Output | Output [3] #> [4]
                    |
                      [4] #> [5]
                    • a<\/li> -
                    • a<\/li> [5] #> [6] <\/ul> | <\/ul> [6] #> #> * Run `testthat::snapshot_accept('snapshotting.Rmd')` to accept the change. #> * Run `testthat::snapshot_review('snapshotting.Rmd')` to interactively review the change. #> Error: #> ! Test failed"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"snapshot-format","dir":"Articles","previous_headings":"Basic workflow","what":"Snapshot format","title":"Snapshot tests","text":"Snapshots recorded using subset markdown. might wonder use markdown? ’s important snapshots readable humans, humans look code reviews. Reviewers often don’t run code still want understand changes. ’s snapshot file generated test : test starts # {test name}, level 1 heading. Within test, snapshot expectation indented four spaces, .e. code, separated ---, horizontal rule.","code":"# bullets
                      • a<\/li> <\/ul> ---
                        • a<\/li> <\/ul>"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"interactive-usage","dir":"Articles","previous_headings":"Basic workflow","what":"Interactive usage","title":"Snapshot tests","text":"snapshot output uses name current test file current test, snapshot expectations don’t really work run interactively console. Since can’t automatically find reference output, instead just print current value manual inspection.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"other-types-of-output","dir":"Articles","previous_headings":"","what":"Other types of output","title":"Snapshot tests","text":"far ’ve focussed snapshot tests output printed console. expect_snapshot() also captures messages, errors, warnings1. following function generates output, message, warning: expect_snapshot() captures : Capturing errors slightly difficult expect_snapshot() fail ’s error: safety valve ensures don’t accidentally write broken code. deliberately snapshot error, ’ll specifically request error = TRUE: code gets longer, like put error = TRUE front ’s little obvious:","code":"f <- function() { print(\"Hello\") message(\"Hi!\") warning(\"How are you?\") } test_that(\"f() makes lots of noise\", { expect_snapshot(f()) }) #> -- Warning: f() makes lots of noise -------------------------------------------- #> Adding new snapshot: #> Code #> f() #> Output #> [1] \"Hello\" #> Message #> Hi! #> Condition #> Warning in `f()`: #> How are you? test_that(\"you can't add a number and a letter\", { expect_snapshot(1 + \"a\") }) #> -- Error: you can't add a number and a letter ---------------------------------- #> `1 + \"a\"` threw an unexpected error. #> Message: non-numeric argument to binary operator #> Class: simpleError/error/condition #> Error: #> ! Test failed test_that(\"you can't add a number and a letter\", { expect_snapshot(1 + \"a\", error = TRUE) }) #> -- Warning: you can't add a number and a letter -------------------------------- #> Adding new snapshot: #> Code #> 1 + \"a\" #> Condition #> Error in `1 + \"a\"`: #> ! non-numeric argument to binary operator test_that(\"you can't add weird things\", { expect_snapshot(error = TRUE, { 1 + \"a\" mtcars + iris mean + sum }) }) #> -- Warning: you can't add weird things ----------------------------------------- #> Adding new snapshot: #> Code #> 1 + \"a\" #> Condition #> Error in `1 + \"a\"`: #> ! non-numeric argument to binary operator #> Code #> mtcars + iris #> Condition #> Error in `Ops.data.frame()`: #> ! '+' only defined for equally-sized data frames #> Code #> mean + sum #> Condition #> Error in `mean + sum`: #> ! non-numeric argument to binary operator"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"snapshotting-values","dir":"Articles","previous_headings":"","what":"Snapshotting values","title":"Snapshot tests","text":"expect_snapshot() used snapshot function records everything: code run, printed output, messages, warnings, errors. care return value rather side-effects, may might use expect_snapshot_value() instead. offers number serialisation approaches provide tradeoff accuracy human readability.","code":"test_that(\"can snapshot a simple list\", { x <- list(a = list(1, 5, 10), b = list(\"elephant\", \"banana\")) expect_snapshot_value(x) }) #> -- Warning: can snapshot a simple list ----------------------------------------- #> Adding new snapshot: #> { #> \"a\": [ #> 1, #> 5, #> 10 #> ], #> \"b\": [ #> \"elephant\", #> \"banana\" #> ] #> }"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"whole-file-snapshotting","dir":"Articles","previous_headings":"","what":"Whole file snapshotting","title":"Snapshot tests","text":"expect_snapshot(), expect_snapshot_output(), expect_snapshot_error(), expect_snapshot_value() use one snapshot file per test file. doesn’t work file types — example, happens want snapshot image? expect_snapshot_file() provides alternative workflow generates one snapshot per expectation, rather one file per test. Assuming ’re test-burger.R snapshot created expect_snapshot_file(code_that_returns_path_to_file(), \"toppings.png\") saved tests/testthat/_snaps/burger/toppings.png. future change code creates different file saved tests/testthat/_snaps/burger/toppings.new.png. Unlike expect_snapshot() friends, expect_snapshot_file() can’t provide automatic diff test fails. Instead ’ll need call snapshot_review(). launches Shiny app allows visually review change approve ’s deliberate: display varies based file type (currently text files, common image files, csv files supported). Sometimes failure occurs non-interactive environment can’t run snapshot_review(), e.g. R CMD check. case, easiest fix retrieve .new file, copy appropriate directory, run snapshot_review() locally. code run CI platform, ’ll need start downloading run “artifact”, contains check folder. cases, don’t expect use expect_snapshot_file() directly. Instead, ’ll use via wrapper best gracefully skip tests differences platform package versions make unlikely generate perfectly reproducible output.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"previous-work","dir":"Articles","previous_headings":"","what":"Previous work","title":"Snapshot tests","text":"first time testthat attempted provide snapshot testing (although ’s first time knew languages called ). section describes previous attempts believe new approach better. verify_output() three main drawbacks: supply path output saved. seems like small issue, thinking good name, managing difference interactive test-time paths introduces surprising amount friction. always overwrites previous result; automatically assuming changes correct. means use git ’s easy accidentally accept unwanted changes. ’s relatively coarse grained, means tests use tend keep growing growing. expect_known_output() finer grained version verify_output() captures output single function. requirement produce path individual expectation makes even painful use. expect_known_value() expect_known_hash() disadvantages expect_known_output(), also produce binary output meaning can’t easily review test differences pull requests.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"test-files","dir":"Articles","previous_headings":"","what":"Test files","title":"Special files","text":"bread butter testthat. Test files live tests/testthat/, start either test- test_, end .r .R. recommend organising test files ’s one--one correspondence files R/ files tests/testthat/ (e.g.) R/myfile.R matching tests/testthat/test-myfile.R. correspondence maintained functions like usethis::use_r() usethis::use_test() taken advantage functions like devtools::test_active_file() devtools::test_coverage_active_file(). Test files executed alphabetical order, strive avoid dependencies test files. principle, able run test files order even time.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"helper-files","dir":"Articles","previous_headings":"","what":"Helper files","title":"Special files","text":"Helper files live tests/testtthat/, start helper, end .r .R. sourced devtools::load_all() (’re available interactively developing packages) test_check() friends (’re available matter tests executed). Helper files useful place functions ’ve extracted repeated code tests, whether test fixtures (vignette(\"test-fixtures\")), custom expectations (vignette(\"custom-expectations\")), skip helpers (vignette(\"skipping\")).","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"setup-files","dir":"Articles","previous_headings":"","what":"Setup files","title":"Special files","text":"Setup files live tests/testthat/, start setup, end .r .R. Typically one setup file , convention, tests/testthat/setup.R. Setup files sourced test_check() friends (’re available matter tests executed), sourced devtools::load_all(). Setup files good place put truly global test setup impractical build every single test might tailored test execution non-interactive remote environments. Examples: Turning behaviour aimed interactive user, messaging writing clipboard. Setting cache folder. setup reversed test execution (.e. needs torn ), recommend maintaining teardown code alongside setup code, setup.R, makes easier ensure stay sync. artificial environment teardown_env() exists magical handle use withr::defer() withr::local_*(). legacy approach (still works, longer recommended) put teardown code tests/testthat/teardown.R. ’s setup.R example reprex package, turn clipboard HTML preview functionality testing: Since just modifying options , can even concise use pre-built function withr::local_options() pass teardown_env() .local_envir:","code":"op <- options(reprex.clipboard = FALSE, reprex.html_preview = FALSE) withr::defer(options(op), teardown_env()) withr::local_options( list(reprex.clipboard = FALSE, reprex.html_preview = FALSE), .local_envir = teardown_env() )"},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"teardown-files","dir":"Articles","previous_headings":"Setup files","what":"Teardown files","title":"Special files","text":"Teardown files live tests/testhat/, start teardown end .r .R. executed tests run, longer recommend using ’s easier check clean every mess make interleave setup tear code described .","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"snapshot-files","dir":"Articles","previous_headings":"","what":"Snapshot files","title":"Special files","text":"Snapshot files live tests/testthat/_snaps/. Snapshot file named automatically based name test file tests/testthat/test-one.R generated tests/testthat/_snaps/one.md. Learn snapshot tests vignette(\"snapshotting\").","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"other-files-and-folders","dir":"Articles","previous_headings":"","what":"Other files and folders","title":"Special files","text":"files folders tests/testthat/ ignored testthat, making good place store persistent test data. Since precise location test/testthat/ directory varies slightly depending ’re running test, recommend creating paths files directories using test_path().","code":""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"test-hygiene","dir":"Articles","previous_headings":"","what":"Test hygiene","title":"Test fixtures","text":"Take nothing memories, leave nothing footprints. ― Chief Si’ahl Ideally, test leave world exactly found . often need make changes order exercise every part code: Create file directory Create resource external system Set R option Set environment variable Change working directory Change aspect tested package’s state can clean changes get back clean slate? Scrupulous attention cleanup just courtesy fastidious. also self-serving. state world test starting state test + 1. Tests change state willy-nilly eventually end interfering ways can difficult debug. tests written implicit assumption starting state, usually whatever tabula rasa means target domain package. accumulate enough sloppy tests, eventually find asking programming equivalent questions like “forgot turn oven?” “didn’t clean dog?”. ’s also important setup cleanup easy use working interactively. test fails, want able quickly recreate exact environment test run can interactively experiment figure went wrong. article introduces powerful technique allows solve problems: test fixtures. ’ll begin introduction tools make fixtures possible, talk exactly test fixture , show examples. Much vignette derived https://www.tidyverse.org/blog/2020/04/self-cleaning-test-fixtures/; first encounter .exit() withr::defer(), ’d recommend starting blog gives gentler introduction. vignette moves little faster since ’s designed reference doc.","code":"library(testthat)"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"foundations","dir":"Articles","previous_headings":"","what":"Foundations","title":"Test fixtures","text":"can talk test fixtures, need lay foundations help understand work. ’ll motivate discussion sloppy() function prints number specific number significant digits adjusting R option: Notice pi prints differently call sloppy(). Calling sloppy() side effect: changes digits option globally, just within scope operations. want avoid1.","code":"sloppy <- function(x, sig_digits) { options(digits = sig_digits) print(x) } pi #> [1] 3.141593 sloppy(pi, 2) #> [1] 3.1 pi #> [1] 3.1"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"on-exit","dir":"Articles","previous_headings":"Foundations","what":"on.exit()","title":"Test fixtures","text":"first function need know base R’s .exit(). .exit() calls code supplied first argument current function exits, regardless whether returns value errors. can use .exit() clean ensuring every mess-making function call paired .exit() call cleans . can use idea turn sloppy() neat(): make use useful pattern options() implements: call options(digits = sig_digits) sets digits option (invisibly) returns previous value digits. can use value restore previous options. .exit() also works tests: three main drawbacks .exit(): always call add = TRUE = FALSE. ensure call added list deferred tasks (instead replaces) added front stack (back, cleanup occurs reverse order setup). arguments matter ’re using multiple .exit() calls, ’s good habit always use avoid potential problems road. doesn’t work outside function test. run following code global environment, won’t get error, cleanup code never run: annoying running tests interactively. can’t program ; .exit() always works inside current function can’t wrap repeated .exit() code helper function. resolve drawbacks, use withr::defer().","code":"neat <- function(x, sig_digits) { op <- options(digits = sig_digits) on.exit(options(op), add = TRUE, after = FALSE) print(x) } pi #> [1] 3.141593 neat(pi, 2) #> [1] 3.1 pi #> [1] 3.141593 test_that(\"can print one digit of pi\", { op <- options(digits = 1) on.exit(options(op), add = TRUE, after = FALSE) expect_output(print(pi), \"3\") }) #> Test passed pi #> [1] 3.141593 op <- options(digits = 1) on.exit(options(op), add = TRUE, after = FALSE)"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"withrdefer","dir":"Articles","previous_headings":"Foundations","what":"withr::defer()","title":"Test fixtures","text":"withr::defer() resolves main drawbacks .exit(). First, behaviour want default; extra arguments needed: Second, works called global environment. Since global environment isn’t perishable, like test environment , call deferred_run() explicitly execute deferred events. can also clear , without running, deferred_clear(). Finally, withr::defer() lets pick function bind clean behaviour . makes possible create helper functions.","code":"neat <- function(x, sig_digits) { op <- options(digits = sig_digits) withr::defer(options(op)) print(x) } withr::defer(print(\"hi\")) #> Setting deferred event(s) on global environment. #> * Execute (and clear) with `deferred_run()`. #> * Clear (without executing) with `deferred_clear()`. withr::deferred_run() #> [1] \"hi\""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"local-helpers","dir":"Articles","previous_headings":"Foundations","what":"“Local” helpers","title":"Test fixtures","text":"Imagine many functions want temporarily set digits option. Wouldn’t nice write helper function automate? Unfortunately can’t write helper .exit(): code doesn’t work cleanup happens soon, local_digits() exits, neat() finishes. Fortunately, withr::defer() allows us solve problem providing envir argument allows control cleanup occurs. exact details works rather complicated, fortunately ’s common pattern can use without understanding details. helper function always env argument defaults parent.frame(), pass second argument defer(): Just like .exit() defer(), helper also works within tests: always call helper functions local_; “local” refers fact state change persists locally, lifetime associated function test.","code":"local_digits <- function(sig_digits) { op <- options(digits = sig_digits) on.exit(options(op), add = TRUE, after = FALSE) } neater <- function(x, sig_digits) { local_digits(1) print(x) } neater(pi) #> [1] 3.141593 local_digits <- function(sig_digits, env = parent.frame()) { op <- options(digits = sig_digits) withr::defer(options(op), env) } neater(pi) #> [1] 3 test_that(\"withr lets us write custom helpers for local state manipulation\", { local_digits(1) expect_output(print(exp(1)), \"3\") local_digits(3) expect_output(print(exp(1)), \"2.72\") }) #> Test passed print(exp(1)) #> [1] 2.718282"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"pre-existing-helpers","dir":"Articles","previous_headings":"Foundations","what":"Pre-existing helpers","title":"Test fixtures","text":"write helper function, make sure check wide range local functions already provided withr: can use withr::local_options() write yet another version neater(): local_*() function companion with_() function, nod (), inspiration withr’s name. won’t use with_*() functions , can learn withr.r-lib.org.","code":"neatest <- function(x, sig_digits) { withr::local_options(list(digits = sig_digits)) print(x) } neatest(pi, 3) #> [1] 3.14"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"test-fixtures","dir":"Articles","previous_headings":"","what":"Test fixtures","title":"Test fixtures","text":"Testing often demonstrated cute little tests functions inputs expected results can inlined. real packages, things aren’t always simple functions often depend global state. example, take variant message() shows message verbose option TRUE. test setting option indeed silence message? cases, ’s possible make global state explicit argument function. example, refactor message2() make verbosity explicit argument: Making external state explicit often worthwhile, makes clear exactly inputs determine outputs function. ’s simply possible many cases. ’s test fixtures come : allow temporarily change global state order test function. Test fixture pre-existing term software engineering world (beyond): test fixture something used consistently test item, device, piece software. — Wikipedia test fixture just local_ function use change state way can reach inside test parts code otherwise challenging. example, ’s use withr::local_options() test fixture test message2():","code":"message2 <- function(...) { if (!isTRUE(getOption(\"verbose\"))) { return() } message(...) } message3 <- function(..., verbose = getOption(\"verbose\")) { if (!isTRUE(verbose)) { return() } message(...) } test_that(\"message2() output depends on verbose option\", { withr::local_options(verbose = TRUE) expect_message(message2(\"Hi!\")) withr::local_options(verbose = FALSE) expect_message(message2(\"Hi!\"), NA) }) #> now dyn.load(\"/home/runner/work/_temp/Library/ellipsis/libs/ellipsis.so\") ... #> now dyn.load(\"/home/runner/work/_temp/Library/fansi/libs/fansi.so\") ... #> now dyn.load(\"/home/runner/work/_temp/Library/utf8/libs/utf8.so\") ... #> Test passed"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"case-study-usethis","dir":"Articles","previous_headings":"Test fixtures","what":"Case study: usethis","title":"Test fixtures","text":"One place use test fixtures extensively usethis package (usethis.r-lib.org), provides functions looking files folders R projects, especially packages. Many functions make sense context package, means test , also working inside R package. need way quickly spin minimal package temporary directory, test functions , destroy . solve problem create test fixture, place R/test-helpers.R ’s ’s available testing interactive experimentation: Note cleanup automatically unfolds opposite order setup. Setup , B, C; cleanup -C, -B, -. important must create directory dir can make working directory; must restore original working directory can delete dir; can’t delete dir ’s still working directory! local_create_package() used 170 tests. ’s one example checks usethis::use_roxygen_md() setup necessary use roxygen2 package, markdown support turned . 3 expectations consult DESCRIPTION file, directly indirectly. ’s convenient local_create_package() creates minimal package, valid DESCRIPTION file, us test . test done — poof! — package gone.","code":"local_create_package <- function(dir = file_temp(), env = parent.frame()) { old_project <- proj_get_() # create new folder and package create_package(dir, open = FALSE) # A withr::defer(fs::dir_delete(dir), envir = env) # -A # change working directory setwd(dir) # B withr::defer(setwd(old_project), envir = env) # -B # switch to new usethis project proj_set(dir) # C withr::defer(proj_set(old_project, force = TRUE), envir = env) # -C dir } test_that(\"use_roxygen_md() adds DESCRIPTION fields\", { pkg <- local_create_package() use_roxygen_md() expect_true(uses_roxygen_md()) expect_equal(desc::desc_get(\"Roxygen\", pkg)[[1]], \"list(markdown = TRUE)\")) expect_true(desc::desc_has_fields(\"RoxygenNote\", pkg)) })"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"scope","dir":"Articles","previous_headings":"","what":"Scope","title":"Test fixtures","text":"far applied test fixture individual tests, ’s also possible apply file package.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"file","dir":"Articles","previous_headings":"Scope","what":"File","title":"Test fixtures","text":"move local_() call outside test_that() block, affect tests come . means calling test fixture top file can change behaviour tests. advantages disadvantages: otherwise called fixture every test, ’ve saved bunch work duplicate code. downside, test fails want recreate failure interactive environment can debug, need remember run setup code top file first. Generally, think ’s better copy paste test fixtures across many tests — sure, adds duplication code, makes debugging test failures much easier.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"package","dir":"Articles","previous_headings":"Scope","what":"Package","title":"Test fixtures","text":"run code test run, can create file called tests/testthat/setup.R. code file needs clean , can use special teardown_env(): Setup code typically best used create external resources needed many tests. ’s best kept minimum manually run interactively debugging tests.","code":"# Run before any test write.csv(\"mtcars.csv\", mtcars) # Run after all tests withr::defer(unlink(\"mtcars.csv\"), teardown_env())"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"other-challenges","dir":"Articles","previous_headings":"","what":"Other challenges","title":"Test fixtures","text":"collection miscellaneous problems don’t know else describe: base functions hard test depend state can’t control. One example interactive(): ’s way write test fixture allows pretend interactive either TRUE FALSE. now usually use rlang::is_interactive() can controlled rlang_interactive option. ’re using test fixture function, careful return. example, write function dir <- create_local_package() shouldn’t return dir, function returns directory longer exist.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"activating","dir":"Articles","previous_headings":"","what":"Activating","title":"testthat 3e","text":"usual way activate 3rd edition add line DESCRIPTION: activate 3rd edition every test package. can also control edition used individual tests testthat::local_edition(): also useful ’ve switched 3rd edition couple tests fail. can use local_edition(2) revert back old behaviour, giving breathing room figure underlying issue.","code":"Config/testthat/edition: 3 test_that(\"I can use the 3rd edition\", { local_edition(3) expect_true(TRUE) }) #> Test passed test_that(\"I want to use the 2nd edition\", { local_edition(2) expect_true(TRUE) }) #> Test passed"},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"changes","dir":"Articles","previous_headings":"","what":"Changes","title":"testthat 3e","text":"three major changes 3rd edition: number outdated functions now deprecated, ’ll warned every time run tests (won’t cause R CMD check fail). testthat longer silently swallows messages; now need deliberately handle . expect_equal() expect_identical() now use waldo package instead identical() .equal(). makes consistent provides enhanced display differences test fails.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"deprecations","dir":"Articles","previous_headings":"Changes","what":"Deprecations","title":"testthat 3e","text":"number outdated functions deprecated. functions recommended number years, introduction edition idea, didn’t good way preventing people using without breaking lot code CRAN. context() formally deprecated. testthat moving away context() favour file names quite time, now ’ll strongly encouraged remove calls tests. expect_is() deprecated favour specific expect_type(), expect_s3_class(), expect_s4_class(). ensures check expected class along expected OO system. old expect_that() syntax now deprecated. overly clever API regretted even release testthat 1.0.0. expect_equivalent() deprecated since now equivalent (HA HA) expect_equal(ignore_attr = TRUE). main difference won’t ignore names; ’ll need explicit unname() deliberately want ignore names. setup() teardown() deprecated favour test fixtures. See vignette(\"test-fixtures\") details. expect_known_output(), expect_known_value(), expect_known_hash(), expect_equal_to_reference() deprecated favour expect_snapshot_output() expect_snapshot_value(). with_mock() local_mock() deprecated; please use with_mocked_bindings() local_mocked_bindings() instead. Fixing deprecation warnings straightforward.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"warnings","dir":"Articles","previous_headings":"Changes","what":"Warnings","title":"testthat 3e","text":"second edition, expect_warning() swallows warnings regardless whether match regexp class: third edition, expect_warning() captures one warning others bubble : can either add additional expectations catch warnings, silence suppressWarnings(): Alternatively, might want capture snapshot test: principle also applies expect_message(), message handling changed radical way, described next.","code":"f <- function() { warning(\"First warning\") warning(\"Second warning\") warning(\"Third warning\") } local_edition(2) expect_warning(f(), \"First\") local_edition(3) expect_warning(f(), \"First\") #> Warning in f(): Second warning #> Warning in f(): Third warning f() %>% expect_warning(\"First\") %>% expect_warning(\"Second\") %>% expect_warning(\"Third\") f() %>% expect_warning(\"First\") %>% suppressWarnings() test_that(\"f() produces expected outputs/messages/warnings\", { expect_snapshot(f()) }) #> Can't compare snapshot to reference when testing interactively. #> i Run `devtools::test()` or `testthat::test_file()` to see changes. #> Current value: #> Code #> f() #> Condition #> Warning in `f()`: #> First warning #> Warning in `f()`: #> Second warning #> Warning in `f()`: #> Third warning #> -- Skip: f() produces expected outputs/messages/warnings ----------------------- #> Reason: empty test"},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"messages","dir":"Articles","previous_headings":"Changes","what":"Messages","title":"testthat 3e","text":"reasons can longer remember, testthat silently ignores messages. inconsistent types output, 3rd edition, now bubble test results. ’ll explicit ignore suppressMessages(), ’re important, test presence expect_message().","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"waldo","dir":"Articles","previous_headings":"Changes","what":"waldo","title":"testthat 3e","text":"Probably biggest day--day difference (biggest reason upgrade!) use waldo::compare() inside expect_equal() expect_identical(). goal waldo find concisely describe difference pair R objects, ’s designed specifically help figure ’s gone wrong unit tests. waldo looks even better console carefully uses colours help highlight differences. use waldo also makes precise difference expect_equal() expect_identical(): expect_equal() sets tolerance waldo ignore small numerical differences arising floating point computation. Otherwise functions identical (HA HA). change likely result work upgrade, waldo can give slightly different results identical() .equal() moderately common situations. believe whole differences meaningful useful, ’ll need handle tweaking tests. following changes likely affect : expect_equal() previously ignored environments formulas functions. like arise testing models. ’s worth thinking correct values , annoying can opt comparison ignore_function_env ignore_formula_env. expect_equal() used combination .equal() home-grown testthat::compare() unfortunately used slightly different definition tolerance. Now expect_equal() always uses definition tolerance everywhere, may require tweaks exising tolerance values. expect_equal() previously ignored timezone differences one object current timezone set implicitly (\"\") set explicitly:","code":"f1 <- factor(letters[1:3]) f2 <- ordered(letters[1:3], levels = letters[1:4]) local_edition(2) expect_equal(f1, f2) #> Error: `f1` not equal to `f2`. #> Attributes: < Component \"class\": Lengths (1, 2) differ (string compare on first 1) > #> Attributes: < Component \"class\": 1 string mismatch > #> Attributes: < Component \"levels\": Lengths (3, 4) differ (string compare on first 3) > local_edition(3) expect_equal(f1, f2) #> Error: `f1` (`actual`) not equal to `f2` (`expected`). #> #> `class(actual)`: \"factor\" #> `class(expected)`: \"ordered\" \"factor\" #> #> `levels(actual)`: \"a\" \"b\" \"c\" #> `levels(expected)`: \"a\" \"b\" \"c\" \"d\" dt1 <- dt2 <- ISOdatetime(2020, 1, 2, 3, 4, 0) attr(dt1, \"tzone\") <- \"\" attr(dt2, \"tzone\") <- Sys.timezone() local_edition(2) expect_equal(dt1, dt2) local_edition(3) expect_equal(dt1, dt2) #> Error: `dt1` (`actual`) not equal to `dt2` (`expected`). #> #> `attr(actual, 'tzone')`: \"\" #> `attr(expected, 'tzone')`: \"UTC\""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"reproducible-output","dir":"Articles","previous_headings":"Changes","what":"Reproducible output","title":"testthat 3e","text":"third edition, test_that() automatically calls local_reproducible_output() automatically sets number options environment variables ensure output reproducible across systems. includes setting: options(crayon.enabled = FALSE) options(cli.unicode = FALSE) crayon cli packages produce raw ASCII output. Sys.setLocale(\"LC_COLLATE\" = \"C\") sorting character vector returns order regardless system language. options(width = 80) print methods always generate output regardless actual console width. See documentation details.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"upgrading","dir":"Articles","previous_headings":"","what":"Upgrading","title":"testthat 3e","text":"changes lend following workflow upgrading 2nd 3rd edition: Activate edition 3. can let usethis::use_testthat(3) . Remove replace deprecated functions, going list . output got noisy, quiet things either capturing suppressing warnings messages. Inspect test outputs objects “equal” anymore.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"alternatives","dir":"Articles","previous_headings":"","what":"Alternatives","title":"testthat 3e","text":"might wonder came idea “edition”, rather creating new package like testthat3. decided making new package 2nd 3rd edition share large amount code, making new package substantially increased maintenance burden: majority bugs ’ve needed fixed two places. ’re programmer languages, might wonder can’t rely semantic versioning. main reason CRAN checks packages use testthat latest version testthat, simply incrementing major version number doesn’t actually help reducing R CMD check failures CRAN.","code":""},{"path":"https://testthat.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Hadley Wickham. Author, maintainer. . Copyright holder, funder. R Core team. Contributor. Implementation utils::recover()","code":""},{"path":"https://testthat.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Wickham H (2011). “testthat: Get Started Testing.” R Journal, 3, 5–10. https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf.","code":"@Article{, author = {Hadley Wickham}, title = {testthat: Get Started with Testing}, journal = {The R Journal}, year = {2011}, volume = {3}, pages = {5--10}, url = {https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf}, }"},{"path":[]},{"path":"https://testthat.r-lib.org/dev/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Unit Testing for R","text":"Testing code can painful tedious, greatly increases quality code. testthat tries make testing fun possible, get visceral satisfaction writing tests. Testing addictive, time. make happen, testthat: Provides functions make easy describe expect function , including catching errors, warnings, messages. Easily integrates existing workflow, whether ’s informal testing command line, building test suites, using R CMD check. Displays test progress visually, showing pass, fail, error every expectation. ’re using terminal recent version RStudio, ’ll even colour output. testthat draws inspiration xUnit family testing packages, well many innovative ruby testing libraries, like rspec, testy, bacon cucumber. testthat popular unit testing package R used thousands CRAN packages. ’re familiar testthat, testing chapter R packages gives good overview, along workflow advice concrete examples.","code":""},{"path":"https://testthat.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Unit Testing for R","text":"","code":"# Install the released version from CRAN install.packages(\"testthat\") # Or the development version from GitHub: # install.packages(\"pak\") pak::pak(\"r-lib/testthat\")"},{"path":"https://testthat.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"Unit Testing for R","text":"easiest way get started usethis. Assuming ’re package directory, just run usethis::use_test(\"name\") create test file, set infrastructure need. ’re using RStudio, press Cmd/Ctrl + Shift + T (run devtools::test() ) run tests package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/CheckReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check reporter: 13 line summary of problems — CheckReporter","title":"Check reporter: 13 line summary of problems — CheckReporter","text":"R CMD check displays last 13 lines result, report designed ensure see something useful .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/DebugReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: start recovery. — DebugReporter","title":"Test reporter: start recovery. — DebugReporter","text":"reporter call modified version recover() broken expectations.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/FailReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: fail at end. — FailReporter","title":"Test reporter: fail at end. — FailReporter","text":"reporter simply throw error tests failed. best combined another reporter, SummaryReporter.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/JunitReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: summary of errors in jUnit XML format. — JunitReporter","title":"Test reporter: summary of errors in jUnit XML format. — JunitReporter","text":"reporter includes detailed results test summaries, written file (stdout) jUnit XML format. can read Jenkins Continuous Integration System report dashboard etc. Requires xml2 package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/JunitReporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Test reporter: summary of errors in jUnit XML format. — JunitReporter","text":"fit jUnit structure, context() becomes name well base classname. test_that() name becomes rest classname. deparsed expect_that() call becomes name. failure, message goes node message argument (first line ) text content (full message). Execution time details also recorded. References jUnit XML format: http://llg.cubic.org/docs/junit/","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/ListReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"List reporter: gather all test results along with elapsed time and\nfile information. — ListReporter","title":"List reporter: gather all test results along with elapsed time and\nfile information. — ListReporter","text":"reporter gathers results, adding additional information test elapsed time, test filename available. useful reporting.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/LocationReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: location — LocationReporter","title":"Test reporter: location — LocationReporter","text":"reporter simply prints location every expectation error. useful trying figure source segfault, want figure code triggers C/C++ breakpoint","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/MinimalReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: minimal. — MinimalReporter","title":"Test reporter: minimal. — MinimalReporter","text":"minimal test reporter provides absolutely minimum amount information: whether expectation succeeded, failed experienced error. want find failures errors actually , need run informative test reporter.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/MultiReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Multi reporter: combine several reporters in one. — MultiReporter","title":"Multi reporter: combine several reporters in one. — MultiReporter","text":"reporter useful use several reporters time, e.g. adding custom reporter without removing current one.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/ProgressReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: interactive progress bar of errors. — ProgressReporter","title":"Test reporter: interactive progress bar of errors. — ProgressReporter","text":"ProgressReporter designed interactive use. goal give actionable insights help understand status code. reporter also praises time--time tests pass. default reporter test_dir(). ParallelProgressReporter similar ProgressReporter, works better packages want parallel tests. CompactProgressReporter minimal version ProgressReporter designed use single files. default reporter test_file().","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/RStudioReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: RStudio — RStudioReporter","title":"Test reporter: RStudio — RStudioReporter","text":"reporter designed output RStudio. produces results easily parsed form.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/Reporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Manage test reporting — Reporter","title":"Manage test reporting — Reporter","text":"job reporter aggregate results files, tests, expectations display informative way. Every testtthat function runs multiple tests provides reporter argument can use override default (selected default_reporter()).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/Reporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Manage test reporting — Reporter","text":"need use Reporter object directly creating new reporter. Currently, creating new Reporters undocumented, want create , need make sure familiar R6 need read source code .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/Reporter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Manage test reporting — Reporter","text":"","code":"path <- testthat_example(\"success\") test_file(path) #> #> ══ Testing test-success.R ════════════════════════════════════════════════ #> #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] #> [ FAIL 0 | WARN 0 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 2 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 3 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] #> #> ── Warning (test-success.R:10:3): some tests have warnings ───────────────────── #> NaNs produced #> Backtrace: #> ▆ #> 1. └─testthat::expect_equal(log(-1), NaN) at test-success.R:10:3 #> 2. └─testthat::quasi_label(enquo(object), label, arg = \"object\") #> 3. └─rlang::eval_bare(expr, quo_get_env(quo)) #> #> ── Skipped tests (1) ───────────────────────────────────────────────────── #> • This test hasn't been written yet (1): test-success.R:6:3 #> #> #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] # Override the default by supplying the name of a reporter test_file(path, reporter = \"minimal\") #> .SW..."},{"path":"https://testthat.r-lib.org/dev/reference/SilentReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: gather all errors silently. — SilentReporter","title":"Test reporter: gather all errors silently. — SilentReporter","text":"reporter quietly runs tests, simply gathering expectations. helpful programmatically inspecting errors test run. can retrieve results expectations() method.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/StopReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: stop on error — StopReporter","title":"Test reporter: stop on error — StopReporter","text":"default reporter used expect_that() run interactively. responds stop()ping failures nothing otherwise. ensure failing test raise error.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/StopReporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Test reporter: stop on error — StopReporter","text":"used quick dirty test, final automated testing R CMD check. Otherwise, use reporter runs tests gives context problem.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/SummaryReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: summary of errors. — SummaryReporter","title":"Test reporter: summary of errors. — SummaryReporter","text":"reporter designed interactive usage: lets know tests run successfully well fully reporting information failures errors.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/SummaryReporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Test reporter: summary of errors. — SummaryReporter","text":"can use max_reports field control maximum number detailed reports produced reporter. useful running auto_test() additional benefit, reporter praise time--time tests pass.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/TapReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: TAP format. — TapReporter","title":"Test reporter: TAP format. — TapReporter","text":"reporter output results Test Anything Protocol (TAP), simple text-based interface testing modules test harness. information TAP, see http://testanything.org","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/TeamcityReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: Teamcity format. — TeamcityReporter","title":"Test reporter: Teamcity format. — TeamcityReporter","text":"reporter output results Teamcity message format. information Teamcity messages, see http://confluence.jetbrains.com/display/TCD7/Build+Script+Interaction++TeamCity","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":null,"dir":"Reference","previous_headings":"","what":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"idea behind auto_test() just leave running develop code. Every time save file automatically tested can easily see changes caused test failures.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"","code":"auto_test( code_path, test_path, reporter = default_reporter(), env = test_env(), hash = TRUE )"},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"code_path path directory containing code test_path path directory containing tests reporter test reporter use env environment execute test suite. hash Passed watch(). FALSE, uses less accurate modification time stamps, faster large files.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"current strategy rerunning tests follows: code changed, files reloaded tests rerun otherwise, new modified test run future, auto_test() might implement one following intelligent alternatives: Use codetools build dependency tree rerun tests dependency changes. Mimic ruby's autotest rerun failing tests pass, rerun tests.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/auto_test_package.html","id":null,"dir":"Reference","previous_headings":"","what":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","title":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","text":"Watches package changes, rerunning tests appropriate.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/auto_test_package.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","text":"","code":"auto_test_package(pkg = \".\", reporter = default_reporter(), hash = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/auto_test_package.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","text":"pkg path package reporter test reporter use hash Passed watch(). FALSE, uses less accurate modification time stamps, faster large files.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":null,"dir":"Reference","previous_headings":"","what":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"functions allow capture side-effects function call including printed output, messages warnings. longer recommend use functions, instead relying expect_message() friends bubble unmatched conditions. just want silence unimportant warnings, use suppressWarnings().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"","code":"capture_condition(code, entrace = FALSE) capture_error(code, entrace = FALSE) capture_expectation(code, entrace = FALSE) capture_message(code, entrace = FALSE) capture_warning(code, entrace = FALSE) capture_messages(code) capture_warnings(code, ignore_deprecation = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"code Code evaluate entrace Whether add backtrace captured condition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"Singular functions (capture_condition, capture_expectation etc) return condition object. capture_messages() capture_warnings return character vector message text.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"","code":"f <- function() { message(\"First\") warning(\"Second\") message(\"Third\") } capture_message(f()) #> > capture_messages(f()) #> Warning: Second #> [1] \"First\\n\" \"Third\\n\" capture_warning(f()) #> First #> capture_warnings(f()) #> First #> Third #> [1] \"Second\" # Condition will capture anything capture_condition(f()) #> >"},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Capture output to console — capture_output","title":"Capture output to console — capture_output","text":"Evaluates code special context output captured, similar capture.output().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Capture output to console — capture_output","text":"","code":"capture_output(code, print = FALSE, width = 80) capture_output_lines(code, print = FALSE, width = 80) testthat_print(x)"},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Capture output to console — capture_output","text":"code Code evaluate. print TRUE result evaluating code visible, print result using testthat_print(). width Number characters per line output. inherit getOption(\"width\") tests always use output width, minimising spurious differences.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Capture output to console — capture_output","text":"capture_output() returns single string. capture_output_lines() returns character vector one entry line","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Capture output to console — capture_output","text":"Results printed using testthat_print() generic, defaults print(), giving ability customise printing object tests, needed.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Capture output to console — capture_output","text":"","code":"capture_output({ cat(\"Hi!\\n\") cat(\"Bye\\n\") }) #> [1] \"Hi!\\nBye\" capture_output_lines({ cat(\"Hi!\\n\") cat(\"Bye\\n\") }) #> [1] \"Hi!\" \"Bye\" capture_output(\"Hi\") #> [1] \"\" capture_output(\"Hi\", print = TRUE) #> [1] \"[1] \\\"Hi\\\"\""},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":null,"dir":"Reference","previous_headings":"","what":"Provide human-readable comparison of two objects — compare","title":"Provide human-readable comparison of two objects — compare","text":"compare similar base::.equal(), somewhat buggy use tolerance. Please use waldo instead.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Provide human-readable comparison of two objects — compare","text":"","code":"compare(x, y, ...) # S3 method for default compare(x, y, ..., max_diffs = 9) # S3 method for character compare( x, y, check.attributes = TRUE, ..., max_diffs = 5, max_lines = 5, width = cli::console_width() ) # S3 method for numeric compare( x, y, tolerance = testthat_tolerance(), check.attributes = TRUE, ..., max_diffs = 9 ) # S3 method for POSIXt compare(x, y, tolerance = 0.001, ..., max_diffs = 9)"},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Provide human-readable comparison of two objects — compare","text":"x, y Objects compare ... Additional arguments used control specifics comparison max_diffs Maximum number differences show check.attributes TRUE, also checks values attributes. max_lines Maximum number lines show difference width Width output device tolerance Numerical tolerance: differences (sense base::.equal()) smaller value ignored. default tolerance sqrt(.Machine$double.eps), unless long doubles available, case test skipped.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Provide human-readable comparison of two objects — compare","text":"","code":"# Character ----------------------------------------------------------------- x <- c(\"abc\", \"def\", \"jih\") compare(x, x) #> Equal y <- paste0(x, \"y\") compare(x, y) #> 3/3 mismatches #> x[1]: \"abc\" #> y[1]: \"abcy\" #> #> x[2]: \"def\" #> y[2]: \"defy\" #> #> x[3]: \"jih\" #> y[3]: \"jihy\" compare(letters, paste0(letters, \"-\")) #> 26/26 mismatches #> x[1]: \"a\" #> y[1]: \"a-\" #> #> x[2]: \"b\" #> y[2]: \"b-\" #> #> x[3]: \"c\" #> y[3]: \"c-\" #> #> x[4]: \"d\" #> y[4]: \"d-\" #> #> x[5]: \"e\" #> y[5]: \"e-\" x <- \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursus tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi non, pulvinar dolor. Donec pretium iaculis nulla, ut interdum sapien ultricies a. \" y <- \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursus tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi non, pulvinar dolor. Donec pretium iaculis nulla, ut interdum sapien ultricies a. \" compare(x, y) #> 1/1 mismatches #> x[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> x[1]: s\\n tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi n #> x[1]: on, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapie #> x[1]: n ultricies a. \" #> y[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> y[1]: s\\n tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi #> y[1]: non, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapi #> y[1]: en ultricies a. \" compare(c(x, x), c(y, y)) #> 2/2 mismatches #> x[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> x[1]: s\\n tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi n #> x[1]: on, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapie #> x[1]: n ultricies a. \" #> y[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> y[1]: s\\n tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi #> y[1]: non, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapi #> y[1]: en ultricies a. \" #> #> x[2]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> x[2]: s\\n tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi n #> x[2]: on, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapie #> x[2]: n ultricies a. \" #> y[2]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> y[2]: s\\n tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi #> y[2]: non, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapi #> y[2]: en ultricies a. \" # Numeric ------------------------------------------------------------------- x <- y <- runif(100) y[sample(100, 10)] <- 5 compare(x, y) #> 10/100 mismatches (average diff: 4.31) #> [18] 0.839 - 5 == -4.16 #> [24] 0.348 - 5 == -4.65 #> [27] 0.757 - 5 == -4.24 #> [29] 0.860 - 5 == -4.14 #> [35] 0.432 - 5 == -4.57 #> [47] 0.917 - 5 == -4.08 #> [61] 0.537 - 5 == -4.46 #> [63] 0.508 - 5 == -4.49 #> [69] 0.900 - 5 == -4.10 #> ... x <- y <- 1:10 x[5] <- NA x[6] <- 6.5 compare(x, y) #> 2/10 mismatches (average diff: 0.5) #> [5] NA - 5 == NA #> [6] 6.5 - 6 == 0.5 # Compare ignores minor numeric differences in the same way # as all.equal. compare(x, x + 1e-9) #> Equal"},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":null,"dir":"Reference","previous_headings":"","what":"Compare two directory states. — compare_state","title":"Compare two directory states. — compare_state","text":"Compare two directory states.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compare two directory states. — compare_state","text":"","code":"compare_state(old, new)"},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compare two directory states. — compare_state","text":"old previous state new current state","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compare two directory states. — compare_state","text":"list containing number changes files added, deleted modified","code":""},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a number greater/less than the expected value? — comparison-expectations","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"code return number greater/less expected value?","code":""},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"","code":"expect_lt(object, expected, label = NULL, expected.label = NULL) expect_lte(object, expected, label = NULL, expected.label = NULL) expect_gt(object, expected, label = NULL, expected.label = NULL) expect_gte(object, expected, label = NULL, expected.label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"object, expected value compare expected bound. label, expected.label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"","code":"a <- 9 expect_lt(a, 10) if (FALSE) { expect_lt(11, 10) } a <- 11 expect_gt(a, 10) if (FALSE) { expect_gt(9, 10) }"},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":null,"dir":"Reference","previous_headings":"","what":"Describe the context of a set of tests. — context","title":"Describe the context of a set of tests. — context","text":"Use context() longer recommended. Instead omit , messages use name file instead. ensures context test file name always sync. context defines set tests test related functionality. Usually one context per file, may multiple contexts single file choose.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Describe the context of a set of tests. — context","text":"","code":"context(desc)"},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Describe the context of a set of tests. — context","text":"desc description context. start capital letter.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Describe the context of a set of tests. — context","text":"context() deprecated third edition, equivalent information instead recorded test file name.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Describe the context of a set of tests. — context","text":"","code":"context(\"String processing\") #> Warning: `context()` was deprecated in the 3rd edition. context(\"Remote procedure calls\") #> Warning: `context()` was deprecated in the 3rd edition."},{"path":"https://testthat.r-lib.org/dev/reference/context_start_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Start test context from a file name — context_start_file","title":"Start test context from a file name — context_start_file","text":"use external reporters","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context_start_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Start test context from a file name — context_start_file","text":"","code":"context_start_file(name)"},{"path":"https://testthat.r-lib.org/dev/reference/context_start_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Start test context from a file name — context_start_file","text":"name file name","code":""},{"path":"https://testthat.r-lib.org/dev/reference/default_reporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve the default reporter — default_reporter","title":"Retrieve the default reporter — default_reporter","text":"defaults : ProgressReporter interactive, non-parallel; override testthat.default_reporter ParallelProgressReporter interactive, parallel packages; override testthat.default_parallel_reporter CompactProgressReporter single-file interactive; override testthat.default_compact_reporter CheckReporter R CMD check; override testthat.default_check_reporter","code":""},{"path":"https://testthat.r-lib.org/dev/reference/default_reporter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve the default reporter — default_reporter","text":"","code":"default_reporter() default_parallel_reporter() default_compact_reporter() check_reporter()"},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":null,"dir":"Reference","previous_headings":"","what":"describe: a BDD testing language — describe","title":"describe: a BDD testing language — describe","text":"simple BDD DSL writing tests. language similar RSpec Ruby Mocha JavaScript. BDD tests read like sentences thus easier understand specification function/component .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"describe: a BDD testing language — describe","text":"","code":"describe(description, code) it(description, code = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"describe: a BDD testing language — describe","text":"description description feature code test code containing specs","code":""},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"describe: a BDD testing language — describe","text":"Tests using describe syntax verify tested code, also document intended behaviour. describe block specifies larger component function contains set specifications. specification defined block. block functions test evaluated environment. can also nested describe blocks. test syntax helps test intended behaviour code. example: want write new function package. Try describe specification first using describe, write code. , start implement tests specification (.e. block). Use describe verify implement right things use test_that() ensure things right.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"describe: a BDD testing language — describe","text":"","code":"describe(\"matrix()\", { it(\"can be multiplied by a scalar\", { m1 <- matrix(1:4, 2, 2) m2 <- m1 * 2 expect_equal(matrix(1:4 * 2, 2, 2), m2) }) it(\"can have not yet tested specs\") }) #> Test passed #> Test passed # Nested specs: ## code addition <- function(a, b) a + b division <- function(a, b) a / b ## specs describe(\"math library\", { describe(\"addition()\", { it(\"can add two numbers\", { expect_equal(1 + 1, addition(1, 1)) }) }) describe(\"division()\", { it(\"can divide two numbers\", { expect_equal(10 / 2, division(10, 2)) }) it(\"can handle division by 0\") #not yet implemented }) }) #> Test passed #> Test passed #> Test passed"},{"path":"https://testthat.r-lib.org/dev/reference/dir_state.html","id":null,"dir":"Reference","previous_headings":"","what":"Capture the state of a directory. — dir_state","title":"Capture the state of a directory. — dir_state","text":"Capture state directory.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/dir_state.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Capture the state of a directory. — dir_state","text":"","code":"dir_state(path, pattern = NULL, hash = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/dir_state.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Capture the state of a directory. — dir_state","text":"path path directory pattern regular expression filter files hash use hash (slow accurate) time stamp (fast less accurate)","code":""},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return the expected value? — equality-expectations","title":"Does code return the expected value? — equality-expectations","text":"functions provide two levels strictness comparing computation reference value. expect_identical() baseline; expect_equal() relaxes test ignore small numeric differences. 2nd edition, expect_identical() uses identical() expect_equal uses .equal(). 3rd edition, functions use waldo. differ expect_equal() sets tolerance = testthat_tolerance() small floating point differences ignored; also implies (e.g.) 1 1L treated equal.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return the expected value? — equality-expectations","text":"","code":"expect_equal( object, expected, ..., tolerance = if (edition_get() >= 3) testthat_tolerance(), info = NULL, label = NULL, expected.label = NULL ) expect_identical( object, expected, info = NULL, label = NULL, expected.label = NULL, ... )"},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return the expected value? — equality-expectations","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ... 3e: passed waldo::compare(). See docs see ways control comparison. 2e: passed compare()/identical(). tolerance 3e: passed waldo::compare(). non-NULL, ignore small floating point differences. uses algorithm .equal() tolerance usually relative (.e. mean(abs(x - y) / mean(abs(y)) < tolerance), except differences small, becomes absolute (.e. mean(abs(x - y) < tolerance). See waldo documentation details. 2e: passed compare(), set. hard reason exactly tolerance means depending precise code path either absolute relative tolerance. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label, expected.label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return the expected value? — equality-expectations","text":"","code":"a <- 10 expect_equal(a, 10) # Use expect_equal() when testing for numeric equality if (FALSE) { expect_identical(sqrt(2) ^ 2, 2) } expect_equal(sqrt(2) ^ 2, 2)"},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":null,"dir":"Reference","previous_headings":"","what":"Evaluate a promise, capturing all types of output. — evaluate_promise","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"Evaluate promise, capturing types output.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"","code":"evaluate_promise(code, print = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"code Code evaluate.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"list containing result result function output string containing output function warnings character vector containing text warning messages character vector containing text message","code":""},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"","code":"evaluate_promise({ print(\"1\") message(\"2\") warning(\"3\") 4 }) #> $result #> [1] 4 #> #> $output #> [1] \"[1] \\\"1\\\"\" #> #> $warnings #> [1] \"3\" #> #> $messages #> [1] \"2\\n\" #>"},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":null,"dir":"Reference","previous_headings":"","what":"The building block of all expect_ functions — expect","title":"The building block of all expect_ functions — expect","text":"Call expect() writing expectations. See vignette(\"custom-expectation\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The building block of all expect_ functions — expect","text":"","code":"expect( ok, failure_message, info = NULL, srcref = NULL, trace = NULL, trace_env = caller_env() )"},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The building block of all expect_ functions — expect","text":"ok TRUE FALSE indicating expectation successful. failure_message Message show expectation failed. info Character vector continuing additional information. Included backward compatibility new expectations use . srcref Location failure. needed explicitly supplied need forward srcref captured elsewhere. trace optional backtrace created rlang::trace_back(). supplied, expectation displayed backtrace. trace_env .null(trace), used automatically generate traceback running test_code()/test_file() trace_env. generally need set wrapping expectation inside another function.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"The building block of all expect_ functions — expect","text":"expectation object. Signals expectation condition continue_test restart.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"The building block of all expect_ functions — expect","text":"expect() creates signals expectation one go, exp_signal() separately signals expectation manually created new_expectation(). Expectations signalled following protocol: expectation failure error, signalled base::stop(). Otherwise, signalled base::signalCondition(). continue_test restart registered. invoked, failing expectations ignored normal control flow resumed run tests.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":null,"dir":"Reference","previous_headings":"","what":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"Compares object expected using .equal() check.attributes = FALSE.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"","code":"expect_equivalent( object, expected, ..., info = NULL, label = NULL, expected.label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ... Passed compare(). info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label, expected.label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"expect_equivalent() deprecated 3rd edition. Instead use expect_equal(ignore_attr = TRUE).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"","code":"#' # expect_equivalent() ignores attributes a <- b <- 1:3 names(b) <- letters[1:3] if (FALSE) { expect_equal(a, b) } expect_equivalent(a, b) #> Warning: `expect_equivalent()` was deprecated in the 3rd edition. #> ℹ Use expect_equal(ignore_attr = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code throw an error, warning, message, or other condition? — expect_error","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"expect_error(), expect_warning(), expect_message(), expect_condition() check code throws error, warning, message, condition message matches regexp, class inherits class. See details. 3rd edition, functions match () single condition. additional non-matching (regexp class used) conditions bubble outside expectation. additional conditions important need catch additional expect_message()/expect_warning() calls; unimportant can ignore suppressMessages()/suppressWarnings(). can tricky test combination different conditions, message followed error. expect_snapshot() often easier alternative complex cases.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"","code":"expect_error( object, regexp = NULL, class = NULL, ..., inherit = TRUE, info = NULL, label = NULL ) expect_warning( object, regexp = NULL, class = NULL, ..., inherit = TRUE, all = FALSE, info = NULL, label = NULL ) expect_message( object, regexp = NULL, class = NULL, ..., inherit = TRUE, all = FALSE, info = NULL, label = NULL ) expect_condition( object, regexp = NULL, class = NULL, ..., inherit = TRUE, info = NULL, label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. regexp Regular expression test . character vector giving regular expression must match error message. NULL, default, asserts error, test specific value. NA, asserts errors, now recommend using expect_no_error() friends instead. Note use message errors/warnings/messages generate. Avoid tests rely specific text generated another package since can easily change. need test text generated another package, either protect test skip_on_cran() use expect_snapshot(). class Instead supplying regular expression, can also supply class name. useful \"classed\" conditions. ... Arguments passed expect_match fixed TRUE, treats regexp string matched exactly (regular expressions). Overrides perl. perl logical. Perl-compatible regexps used? inherit Whether match regexp class across ancestry chained errors. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use . DEPRECATED need test multiple warnings/messages now need use multiple calls expect_message()/ expect_warning()","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"regexp = NA, value first argument; otherwise captured condition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"testing-message-vs-class","dir":"Reference","previous_headings":"","what":"Testing message vs class","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"checking code generates error, important check error one expect. two ways . first way simplest: just provide regexp match fragment error message. easy, fragile, test fail error message changes (even error). robust way test class error, one. can learn custom conditions https://adv-r.hadley.nz/conditions.html#custom-conditions, short, errors S3 classes can generate custom class check using class instead regexp. using expect_error() check error message formatted way makes sense human, recommend using expect_snapshot() instead.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"","code":"# Errors ------------------------------------------------------------------ f <- function() stop(\"My error!\") expect_error(f()) expect_error(f(), \"My error!\") # You can use the arguments of grepl to control the matching expect_error(f(), \"my error!\", ignore.case = TRUE) # Note that `expect_error()` returns the error object so you can test # its components if needed err <- expect_error(rlang::abort(\"a\", n = 10)) expect_equal(err$n, 10) # Warnings ------------------------------------------------------------------ f <- function(x) { if (x < 0) { warning(\"*x* is already negative\") return(x) } -x } expect_warning(f(-1)) expect_warning(f(-1), \"already negative\") expect_warning(f(1), NA) # To test message and output, store results to a variable expect_warning(out <- f(-1), \"already negative\") expect_equal(out, -1) # Messages ------------------------------------------------------------------ f <- function(x) { if (x < 0) { message(\"*x* is already negative\") return(x) } -x } expect_message(f(-1)) expect_message(f(-1), \"already negative\") expect_message(f(1), NA)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a visible or invisible object? — expect_invisible","title":"Does code return a visible or invisible object? — expect_invisible","text":"Use test whether function returns visible invisible output. Typically use check functions called primarily side-effects return data argument invisibly.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a visible or invisible object? — expect_invisible","text":"","code":"expect_invisible(call, label = NULL) expect_visible(call, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a visible or invisible object? — expect_invisible","text":"call function call. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code return a visible or invisible object? — expect_invisible","text":"evaluated call, invisibly.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a visible or invisible object? — expect_invisible","text":"","code":"expect_invisible(x <- 10) expect_visible(x) # Typically you'll assign the result of the expectation so you can # also check that the value is as you expect. greet <- function(name) { message(\"Hi \", name) invisible(name) } out <- expect_invisible(greet(\"Hadley\")) #> Hi Hadley expect_equal(out, \"Hadley\")"},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":null,"dir":"Reference","previous_headings":"","what":"Does an object inherit from a given class? — expect_is","title":"Does an object inherit from a given class? — expect_is","text":"expect_is() older form uses inherits() without checking whether x S3, S4, neither. Instead, recommend using expect_type(), expect_s3_class() expect_s4_class() clearly convey intent.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does an object inherit from a given class? — expect_is","text":"","code":"expect_is(object, class, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does an object inherit from a given class? — expect_is","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. class Either character vector class names, expect_s3_class() expect_s4_class(), NA assert object S3 S4 object.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Does an object inherit from a given class? — expect_is","text":"expect_is() formally deprecated 3rd edition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Expectations: is the output or the value equal to a known good value? — expect_known_output","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"complex printed output objects, often challenging describe exactly expect see. expect_known_value() expect_known_output() provide slightly weaker guarantee, simply asserting values changed since last time ran .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"","code":"expect_known_output( object, file, update = TRUE, ..., info = NULL, label = NULL, print = FALSE, width = 80 ) expect_known_value( object, file, update = TRUE, ..., info = NULL, label = NULL, version = 2 ) expect_known_hash(object, hash = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"file File path known value/output stored. update file updated? Defaults TRUE, expectation notice changes first failure, see modified files git. ... Passed waldo::compare(). info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. print TRUE result evaluating code visible, print result using testthat_print(). width Number characters per line output. inherit getOption(\"width\") tests always use output width, minimising spurious differences. version serialization format version use. default, 2, default format R 1.4.0 3.5.3. Version 3 became default R 3.6.0 can read R versions 3.5.0 higher. hash Known hash value. Leave empty informed use test output.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"expectations used conjunction git, otherwise way revert previous values. Git particularly useful conjunction expect_known_output() diffs show exactly changed. Note known values updates updated running tests interactively. R CMD check clones package source changes reference files occur temporary directory, synchronised back source package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"expect_known_output() friends deprecated 3rd edition; please use expect_snapshot_output() friends instead.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"","code":"tmp <- tempfile() # The first run always succeeds expect_known_output(mtcars[1:10, ], tmp, print = TRUE) #> Warning: `expect_known_output()` was deprecated in the 3rd edition. #> ℹ Please use `expect_snapshot_output()` instead #> Warning: Creating reference output # Subsequent runs will succeed only if the file is unchanged # This will succeed: expect_known_output(mtcars[1:10, ], tmp, print = TRUE) #> Warning: `expect_known_output()` was deprecated in the 3rd edition. #> ℹ Please use `expect_snapshot_output()` instead if (FALSE) { # This will fail expect_known_output(mtcars[1:9, ], tmp, print = TRUE) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector with the specified length? — expect_length","title":"Does code return a vector with the specified length? — expect_length","text":"code return vector specified length?","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector with the specified length? — expect_length","text":"","code":"expect_length(object, n)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector with the specified length? — expect_length","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. n Expected length.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector with the specified length? — expect_length","text":"","code":"expect_length(1, 1) expect_length(1:10, 10) if (FALSE) { expect_length(1:10, 1) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_less_than.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated numeric comparison functions — expect_less_than","title":"Deprecated numeric comparison functions — expect_less_than","text":"functions deprecated favour concise expect_gt() expect_lt().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_less_than.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deprecated numeric comparison functions — expect_less_than","text":"","code":"expect_less_than(...) expect_more_than(...)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_less_than.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deprecated numeric comparison functions — expect_less_than","text":"... arguments passed expect_lt()/expect_gt().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":null,"dir":"Reference","previous_headings":"","what":"Does a string match a regular expression? — expect_match","title":"Does a string match a regular expression? — expect_match","text":"string match regular expression?","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does a string match a regular expression? — expect_match","text":"","code":"expect_match( object, regexp, perl = FALSE, fixed = FALSE, ..., all = TRUE, info = NULL, label = NULL ) expect_no_match( object, regexp, perl = FALSE, fixed = FALSE, ..., all = TRUE, info = NULL, label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does a string match a regular expression? — expect_match","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. regexp Regular expression test . perl logical. Perl-compatible regexps used? fixed TRUE, treats regexp string matched exactly (regular expressions). Overrides perl. ... Arguments passed base::grepl ignore.case FALSE, pattern matching case sensitive TRUE, case ignored matching. useBytes logical. TRUE matching done byte--byte rather character--character. See ‘Details’. elements actual value match regexp (TRUE), one need match (FALSE). info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Does a string match a regular expression? — expect_match","text":"expect_match() wrapper around grepl(). See documentation detail individual arguments. expect_no_match() provides complementary case, checking string match regular expression.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Does a string match a regular expression? — expect_match","text":"expect_no_match(): Check string match regular expression.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does a string match a regular expression? — expect_match","text":"","code":"expect_match(\"Testing is fun\", \"fun\") expect_match(\"Testing is fun\", \"f.n\") expect_no_match(\"Testing is fun\", \"horrible\") if (FALSE) { expect_match(\"Testing is fun\", \"horrible\") # Zero-length inputs always fail expect_match(character(), \".\") }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector with (given) names? — expect_named","title":"Does code return a vector with (given) names? — expect_named","text":"can either check presence names (leaving expected blank), specific names (supplying vector names), absence names (NULL).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector with (given) names? — expect_named","text":"","code":"expect_named( object, expected, ignore.order = FALSE, ignore.case = FALSE, info = NULL, label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector with (given) names? — expect_named","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. expected Character vector expected names. Leave missing match names. Use NULL check absence names. ignore.order TRUE, sorts names comparing ignore effect order. ignore.case TRUE, lowercases names ignore effect case. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector with (given) names? — expect_named","text":"","code":"x <- c(a = 1, b = 2, c = 3) expect_named(x) expect_named(x, c(\"a\", \"b\", \"c\")) # Use options to control sensitivity expect_named(x, c(\"B\", \"C\", \"A\"), ignore.order = TRUE, ignore.case = TRUE) # Can also check for the absence of names with NULL z <- 1:4 expect_named(z, NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code run without error, warning, message, or other condition? — expect_no_error","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"expectations opposite expect_error(), expect_warning(), expect_message(), expect_condition(). assert absence error, warning, message, respectively.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"","code":"expect_no_error(object, ..., message = NULL, class = NULL) expect_no_warning(object, ..., message = NULL, class = NULL) expect_no_message(object, ..., message = NULL, class = NULL) expect_no_condition(object, ..., message = NULL, class = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ... dots future extensions must empty. message, class default, message = NULL, class = NULL, fail error/warning/message/condition. many cases, particularly testing warnings messages, want specific condition hoping see, .e. condition motivated write test. Similar expect_error() friends, can specify message (regular expression message condition must match) /class (class condition must inherit ). ensures message/warnings want never recur, allowing new messages/warnings bubble deal . Note use message errors/warnings/messages generate, base R generates (tend stable). Avoid tests rely specific text generated another package since can easily change. need test text generated another package, either protect test skip_on_cran() use expect_snapshot().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"","code":"expect_no_warning(1 + 1) foo <- function(x) { warning(\"This is a problem!\") } # warning doesn't match so bubbles up: expect_no_warning(foo(), message = \"bananas\") #> Warning: This is a problem! # warning does match so causes a failure: try(expect_no_warning(foo(), message = \"problem\")) #> Error : Expected `foo()` to run without any warnings matching pattern 'problem'. #> ℹ Actually got a with text: #> This is a problem!"},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return NULL? — expect_null","title":"Does code return NULL? — expect_null","text":"special case NULL singleton possible check either expect_equal(x, NULL) expect_type(x, \"NULL\").","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return NULL? — expect_null","text":"","code":"expect_null(object, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return NULL? — expect_null","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return NULL? — expect_null","text":"","code":"x <- NULL y <- 10 expect_null(x) show_failure(expect_null(y)) #> Failed expectation: #> `y` is not NULL #> #> `actual` is a double vector (10) #> `expected` is NULL"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code print output to the console? — expect_output","title":"Does code print output to the console? — expect_output","text":"Test output produced print() cat(). best used simple output; complex cases use expect_snapshot().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code print output to the console? — expect_output","text":"","code":"expect_output( object, regexp = NULL, ..., info = NULL, label = NULL, width = 80 )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code print output to the console? — expect_output","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. regexp Regular expression test . character vector giving regular expression must match output. NULL, default, asserts output, check specific value. NA, asserts output. ... Arguments passed expect_match elements actual value match regexp (TRUE), one need match (FALSE). fixed TRUE, treats regexp string matched exactly (regular expressions). Overrides perl. perl logical. Perl-compatible regexps used? info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use . width Number characters per line output. inherit getOption(\"width\") tests always use output width, minimising spurious differences.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code print output to the console? — expect_output","text":"first argument, invisibly.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code print output to the console? — expect_output","text":"","code":"str(mtcars) #> 'data.frame':\t32 obs. of 11 variables: #> $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... #> $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... #> $ disp: num 160 160 108 258 360 ... #> $ hp : num 110 110 93 110 175 105 245 62 95 123 ... #> $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... #> $ wt : num 2.62 2.88 2.32 3.21 3.44 ... #> $ qsec: num 16.5 17 18.6 19.4 17 ... #> $ vs : num 0 0 1 1 0 1 0 1 1 1 ... #> $ am : num 1 1 1 0 0 0 0 0 0 0 ... #> $ gear: num 4 4 4 3 3 3 3 4 4 4 ... #> $ carb: num 4 4 1 1 2 1 4 2 2 4 ... expect_output(str(mtcars), \"32 obs\") expect_output(str(mtcars), \"11 variables\") # You can use the arguments of grepl to control the matching expect_output(str(mtcars), \"11 VARIABLES\", ignore.case = TRUE) expect_output(str(mtcars), \"$ mpg\", fixed = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Expectations: is the output or the value equal to a known good value? — expect_output_file","title":"Expectations: is the output or the value equal to a known good value? — expect_output_file","text":"expect_output_file() behaves identically expect_known_output().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_output_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Expectations: is the output or the value equal to a known good value? — expect_output_file","text":"","code":"expect_output_file( object, file, update = TRUE, ..., info = NULL, label = NULL, print = FALSE, width = 80 )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output_file.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Expectations: is the output or the value equal to a known good value? — expect_output_file","text":"expect_output_file() deprecated 3rd edition; please use expect_snapshot_output() friends instead.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a reference to the expected object? — expect_reference","title":"Does code return a reference to the expected object? — expect_reference","text":"expect_reference() compares underlying memory addresses two symbols. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a reference to the expected object? — expect_reference","text":"","code":"expect_reference( object, expected, info = NULL, label = NULL, expected.label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a reference to the expected object? — expect_reference","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label, expected.label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Does code return a reference to the expected object? — expect_reference","text":"expect_reference() deprecated third edition. know , really need behaviour, just use is_reference() directly: expect_true(rlang::is_reference(x, y)).","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector containing the expected values? — expect_setequal","title":"Does code return a vector containing the expected values? — expect_setequal","text":"expect_setequal(x, y) tests every element x occurs y, every element y occurs x. expect_contains(x, y) tests x contains every element y (.e. y subset x). expect_in(x, y) tests every element x y (.e. x subset y). expect_mapequal(x, y) tests x y names, x[names(y)] equals y.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector containing the expected values? — expect_setequal","text":"","code":"expect_setequal(object, expected) expect_mapequal(object, expected) expect_contains(object, expected) expect_in(object, expected)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector containing the expected values? — expect_setequal","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Does code return a vector containing the expected values? — expect_setequal","text":"Note expect_setequal() ignores names, warned object expected .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector containing the expected values? — expect_setequal","text":"","code":"expect_setequal(letters, rev(letters)) show_failure(expect_setequal(letters[-1], rev(letters))) #> Failed expectation: #> letters[-1] (`actual`) and rev(letters) (`expected`) don't have the same values. #> * Only in `actual`: \"a\" #> x <- list(b = 2, a = 1) expect_mapequal(x, list(a = 1, b = 2)) show_failure(expect_mapequal(x, list(a = 1))) #> Failed expectation: #> Names absent from `expected`: \"b\", show_failure(expect_mapequal(x, list(a = 1, b = \"x\"))) #> Failed expectation: #> act$val[exp_nms] (`actual`) not equal to exp$val (`expected`). #> #> `actual$b` is a double vector (2) #> `expected$b` is a character vector ('x') show_failure(expect_mapequal(x, list(a = 1, b = 2, c = 3))) #> Failed expectation: #> Names absent from `object`: \"c\","},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code execute silently? — expect_silent","title":"Does code execute silently? — expect_silent","text":"Checks code produces output, messages, warnings.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code execute silently? — expect_silent","text":"","code":"expect_silent(object)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code execute silently? — expect_silent","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code execute silently? — expect_silent","text":"first argument, invisibly.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code execute silently? — expect_silent","text":"","code":"expect_silent(\"123\") f <- function() { message(\"Hi!\") warning(\"Hey!!\") print(\"OY!!!\") } if (FALSE) { expect_silent(f()) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot testing — expect_snapshot","title":"Snapshot testing — expect_snapshot","text":"Snapshot tests (aka golden tests) similar unit tests except expected result stored separate file managed testthat. Snapshot tests useful expected value large, intent code something can verified human (e.g. useful error message). Learn vignette(\"snapshotting\"). expect_snapshot() runs code executed console, records results, including output, messages, warnings, errors. just want compare result, try expect_snapshot_value().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot testing — expect_snapshot","text":"","code":"expect_snapshot( x, cran = FALSE, error = FALSE, transform = NULL, variant = NULL, cnd_class = FALSE )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot testing — expect_snapshot","text":"x Code evaluate. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. error expect code throw error? expectation fail (even CRAN) unexpected error thrown expected error thrown. transform Optionally, function scrub sensitive stochastic text output. take character vector lines input return modified character vector output. variant non-NULL, results saved _snaps/{variant}/{test.md}, variant must single string suitable use directory name. can use variants deal cases snapshot output varies want capture test variations. Common use cases include variations operating system, R version, version key dependency. Variants advanced feature. use , need carefully think testing strategy ensure important variants covered automated tests, ensure way get snapshot changes CI system back repo. cnd_class Whether include class messages, warnings, errors snapshot. specific class included, .e. first element class(cnd).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":"workflow","dir":"Reference","previous_headings":"","what":"Workflow","title":"Snapshot testing — expect_snapshot","text":"first time run snapshot expectation run x, capture results, record tests/testthat/_snaps/{test}.md. test file gets snapshot file, e.g. test-foo.R get _snaps/foo.md. important review Markdown files commit git. designed human readable, always review new additions ensure salient information captured. also carefully reviewed pull requests, make sure snapshots updated expected way. subsequent runs, result x compared value stored disk. different, expectation fail, new file _snaps/{test}.new.md created. change deliberate, can approve change snapshot_accept() tests pass next time run . Note snapshotting can work executing complete test file (test_file(), test_dir(), friends) otherwise way figure snapshot path. run snapshot tests interactively, just display current value.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot testing for whole files — expect_snapshot_file","title":"Snapshot testing for whole files — expect_snapshot_file","text":"Whole file snapshot testing designed testing objects convenient textual representation, initial support images (.png, .jpg, .svg), data frames (.csv), text files (.R, .txt, .json, ...). first time expect_snapshot_file() run, create _snaps/{test}/{name}.{ext} containing reference output. Future runs compared reference: different, test fail new results saved _snaps/{test}/{name}.new.{ext}. review failures, call snapshot_review(). generally expect function used via wrapper takes care ensuring output reproducible possible, e.g. automatically skipping tests known images reproduced exactly.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot testing for whole files — expect_snapshot_file","text":"","code":"expect_snapshot_file( path, name = basename(path), binary = lifecycle::deprecated(), cran = FALSE, compare = NULL, transform = NULL, variant = NULL ) announce_snapshot_file(path, name = basename(path)) compare_file_binary(old, new) compare_file_text(old, new)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot testing for whole files — expect_snapshot_file","text":"path Path file snapshot. Optional announce_snapshot_file() name supplied. name Snapshot name, taken path default. binary Please use compare argument instead. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. compare function used compare snapshot files. take two inputs, paths old new snapshot, return either TRUE FALSE. defaults compare_file_text name extension .r, .R, .Rmd, .md, .txt, otherwise uses compare_file_binary. compare_file_binary() compares byte--byte compare_file_text() compares lines--line, ignoring difference Windows Mac/Linux line endings. transform Optionally, function scrub sensitive stochastic text output. take character vector lines input return modified character vector output. variant -NULL, results saved _snaps/{variant}/{test}/{name}.{ext}. allows create different snapshots different scenarios, like different operating systems different R versions. old, new Paths old new snapshot files.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"announcing-snapshots","dir":"Reference","previous_headings":"","what":"Announcing snapshots","title":"Snapshot testing for whole files — expect_snapshot_file","text":"testthat automatically detects dangling snapshots written _snaps directory longer corresponding R code generate . dangling files automatically deleted clutter snapshot directory. However want preserve snapshot files R code executed unexpected error skip(). Let testthat know files calling announce_snapshot_file() expect_snapshot_file().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Snapshot testing for whole files — expect_snapshot_file","text":"","code":"# To use expect_snapshot_file() you'll typically need to start by writing # a helper function that creates a file from your code, returning a path save_png <- function(code, width = 400, height = 400) { path <- tempfile(fileext = \".png\") png(path, width = width, height = height) on.exit(dev.off()) code path } path <- save_png(plot(1:5)) path #> [1] \"/tmp/RtmphshBqb/file19fb57bb5eb4.png\" if (FALSE) { expect_snapshot_file(save_png(hist(mtcars$mpg)), \"plot.png\") } # You'd then also provide a helper that skips tests where you can't # be sure of producing exactly the same output expect_snapshot_plot <- function(name, code) { # Other packages might affect results skip_if_not_installed(\"ggplot2\", \"2.0.0\") # Or maybe the output is different on some operation systems skip_on_os(\"windows\") # You'll need to carefully think about and experiment with these skips name <- paste0(name, \".png\") # Announce the file before touching `code`. This way, if `code` # unexpectedly fails or skips, testthat will not auto-delete the # corresponding snapshot file. announce_snapshot_file(name = name) path <- save_png(code) expect_snapshot_file(path, name) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot helpers — expect_snapshot_output","title":"Snapshot helpers — expect_snapshot_output","text":"snapshotting functions questioning developed expect_snapshot() sure still role play. expect_snapshot_output() captures just output printed console. expect_snapshot_error() captures error message optionally checks class. expect_snapshot_warning() captures warning message optionally checks class.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot helpers — expect_snapshot_output","text":"","code":"expect_snapshot_output(x, cran = FALSE, variant = NULL) expect_snapshot_error(x, class = \"error\", cran = FALSE, variant = NULL) expect_snapshot_warning(x, class = \"warning\", cran = FALSE, variant = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot helpers — expect_snapshot_output","text":"x Code evaluate. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. variant non-NULL, results saved _snaps/{variant}/{test.md}, variant must single string suitable use directory name. can use variants deal cases snapshot output varies want capture test variations. Common use cases include variations operating system, R version, version key dependency. Variants advanced feature. use , need carefully think testing strategy ensure important variants covered automated tests, ensure way get snapshot changes CI system back repo. class Class expected error warning. expectation always fail (even CRAN) error class seen executing x.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_value.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot testing for values — expect_snapshot_value","title":"Snapshot testing for values — expect_snapshot_value","text":"Captures result function, flexibly serializing text representation stored snapshot file. See expect_snapshot() details snapshot testing.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_value.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot testing for values — expect_snapshot_value","text":"","code":"expect_snapshot_value( x, style = c(\"json\", \"json2\", \"deparse\", \"serialize\"), cran = FALSE, tolerance = testthat_tolerance(), ..., variant = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_value.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot testing for values — expect_snapshot_value","text":"x Code evaluate. style Serialization style use: json uses jsonlite::fromJSON() jsonlite::toJSON(). produces simplest output works relatively simple objects. json2 uses jsonlite::serializeJSON() jsonlite::unserializeJSON() verbose work wider range type. deparse uses deparse(), generates depiction object using R code. serialize() produces binary serialization object using serialize(). guaranteed work R object, produces completely opaque serialization. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. tolerance Numerical tolerance: differences (sense base::.equal()) smaller value ignored. default tolerance sqrt(.Machine$double.eps), unless long doubles available, case test skipped. ... Passed waldo::compare() can control details comparison. variant non-NULL, results saved _snaps/{variant}/{test.md}, variant must single string suitable use directory name. can use variants deal cases snapshot output varies want capture test variations. Common use cases include variations operating system, R version, version key dependency. Variants advanced feature. use , need carefully think testing strategy ensure important variants covered automated tests, ensure way get snapshot changes CI system back repo.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_success.html","id":null,"dir":"Reference","previous_headings":"","what":"Tools for testing expectations — expect_success","title":"Tools for testing expectations — expect_success","text":"Use expectations test expectations. Use show_failure() examples print failure message without throwing error.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_success.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tools for testing expectations — expect_success","text":"","code":"expect_success(expr) expect_failure(expr, message = NULL, ...) show_failure(expr)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_success.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tools for testing expectations — expect_success","text":"expr Expression evaluates single expectation. message Check failure message matches regexp. ... arguments passed expect_match().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":null,"dir":"Reference","previous_headings":"","what":"Expect that a condition holds. — expect_that","title":"Expect that a condition holds. — expect_that","text":"old style testing longer encouraged.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Expect that a condition holds. — expect_that","text":"","code":"expect_that(object, condition, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Expect that a condition holds. — expect_that","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. condition, function returns whether condition met, , error message display. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Expect that a condition holds. — expect_that","text":"(internal) expectation result invisible list","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Expect that a condition holds. — expect_that","text":"style testing formally deprecated 3rd edition. Use specific expect_ function instead.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Expect that a condition holds. — expect_that","text":"","code":"expect_that(5 * 2, equals(10)) #> Warning: `expect_that()` was deprecated in the 3rd edition. expect_that(sqrt(2) ^ 2, equals(2)) #> Warning: `expect_that()` was deprecated in the 3rd edition. if (FALSE) { expect_that(sqrt(2) ^ 2, is_identical_to(2)) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector with the expected size and/or prototype? — expect_vector","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"expect_vector() thin wrapper around vctrs::vec_assert(), converting results function expectations used testthat. means used vctrs ptype (prototype) size. See details https://vctrs.r-lib.org/articles/type-size.html","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"","code":"expect_vector(object, ptype = NULL, size = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ptype (Optional) Vector prototype test . size-0 (empty) generalised vector. size (Optional) Size check .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"","code":"if (requireNamespace(\"vctrs\") && packageVersion(\"vctrs\") > \"0.1.0.9002\") { expect_vector(1:10, ptype = integer(), size = 10) show_failure(expect_vector(1:10, ptype = integer(), size = 5)) show_failure(expect_vector(1:10, ptype = character(), size = 5)) } #> Failed expectation: #> `1:10` must have size 5, not size 10. #> Failed expectation: #> `1:10` must be a vector with type . #> Instead, it has type ."},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct an expectation object — expectation","title":"Construct an expectation object — expectation","text":"advanced use . creating expectation, call expect() instead. See vignette(\"custom-expectation\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct an expectation object — expectation","text":"","code":"expectation(type, message, srcref = NULL, trace = NULL) new_expectation( type, message, ..., srcref = NULL, trace = NULL, .subclass = NULL ) exp_signal(exp) is.expectation(x)"},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct an expectation object — expectation","text":"type Expectation type. Must one \"success\", \"failure\", \"error\", \"skip\", \"warning\". message Message describing test failure srcref Optional srcref giving location test. trace optional backtrace created rlang::trace_back(). supplied, expectation displayed backtrace. ... Additional attributes expectation object. .subclass optional subclass expectation object. exp expectation object, created new_expectation(). x object test class membership","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Construct an expectation object — expectation","text":"Create expectation expectation() new_expectation() signal exp_signal().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":null,"dir":"Reference","previous_headings":"","what":"Default expectations that always succeed or fail. — fail","title":"Default expectations that always succeed or fail. — fail","text":"allow manually trigger success failure. Failure particularly useful pre-condition mark test yet implemented.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default expectations that always succeed or fail. — fail","text":"","code":"fail( message = \"Failure has been forced\", info = NULL, trace_env = caller_env() ) succeed(message = \"Success has been forced\", info = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default expectations that always succeed or fail. — fail","text":"message string display. info Character vector continuing additional information. Included backward compatibility new expectations use . trace_env .null(trace), used automatically generate traceback running test_code()/test_file() trace_env. generally need set wrapping expectation inside another function.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Default expectations that always succeed or fail. — fail","text":"","code":"if (FALSE) { test_that(\"this test fails\", fail()) test_that(\"this test succeeds\", succeed()) }"},{"path":"https://testthat.r-lib.org/dev/reference/find_reporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Find reporter object given name or object. — find_reporter","title":"Find reporter object given name or object. — find_reporter","text":"found, return informative error message. Pass character vector create MultiReporter composed individual reporters. return null given NULL.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_reporter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Find reporter object given name or object. — find_reporter","text":"","code":"find_reporter(reporter)"},{"path":"https://testthat.r-lib.org/dev/reference/find_reporter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Find reporter object given name or object. — find_reporter","text":"reporter name reporter(s), reporter object(s)","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":null,"dir":"Reference","previous_headings":"","what":"Find test files — find_test_scripts","title":"Find test files — find_test_scripts","text":"Find test files","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Find test files — find_test_scripts","text":"","code":"find_test_scripts( path, filter = NULL, invert = FALSE, ..., full.names = TRUE, start_first = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Find test files — find_test_scripts","text":"path path tests filter NULL, tests file names matching regular expression executed. Matching performed file name stripped \"test-\" \".R\". invert TRUE return files match. ... Additional arguments passed grepl() control filtering. start_first character vector file patterns (globs, see utils::glob2rx()). patterns file names (base names), whole paths. testthat starts files matching first pattern first, ones matching second, etc. rest files, alphabetically. Parallel tests tend finish quicker start slowest files first. NULL means alphabetical order.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Find test files — find_test_scripts","text":"character vector paths","code":""},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"See https://adv-r.hadley.nz/oo.html overview R's OO systems, vocabulary used . expect_type(x, type) checks typeof(x) type. expect_s3_class(x, class) checks x S3 object inherits() class expect_s3_class(x, NA) checks x S3 object. expect_s4_class(x, class) checks x S4 object () class. expect_s4_class(x, NA) checks x S4 object. See expect_vector() testing properties objects created vctrs.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"","code":"expect_type(object, type) expect_s3_class(object, class, exact = FALSE) expect_s4_class(object, class)"},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. type String giving base type (returned typeof()). class Either character vector class names, expect_s3_class() expect_s4_class(), NA assert object S3 S4 object. exact FALSE, default, checks object inherits class. TRUE, checks object class identical class.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"","code":"x <- data.frame(x = 1:10, y = \"x\", stringsAsFactors = TRUE) # A data frame is an S3 object with class data.frame expect_s3_class(x, \"data.frame\") show_failure(expect_s4_class(x, \"data.frame\")) #> Failed expectation: #> `x` is not an S4 object # A data frame is built from a list: expect_type(x, \"list\") # An integer vector is an atomic vector of type \"integer\" expect_type(x$x, \"integer\") # It is not an S3 object show_failure(expect_s3_class(x$x, \"integer\")) #> Failed expectation: #> x$x is not an S3 object # Above, we requested data.frame() converts strings to factors: show_failure(expect_type(x$y, \"character\")) #> Failed expectation: #> x$y has type 'integer', not 'character'. expect_s3_class(x$y, \"factor\") expect_type(x$y, \"integer\")"},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":null,"dir":"Reference","previous_headings":"","what":"Is an error informative? — is_informative_error","title":"Is an error informative? — is_informative_error","text":"is_informative_error() generic predicate indicates whether testthat users explicitly test error class. Since longer recommend , generic deprecated.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is an error informative? — is_informative_error","text":"","code":"is_informative_error(x, ...)"},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is an error informative? — is_informative_error","text":"x error object. ... dots future extensions must empty.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Is an error informative? — is_informative_error","text":"classes hard-coded uninformative: simpleError rlang_error unless subclass detected Rcpp::eval_error Rcpp::exception","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_testing.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine testing status — is_testing","title":"Determine testing status — is_testing","text":"functions help determine code running particular testing context: is_testing() TRUE inside test. is_snapshot() TRUE inside snapshot test is_checking() TRUE inside R CMD check (.e. test_check()). is_parallel() TRUE tests run parallel. testing_package() gives name package tested. common use functions compute default value quiet argument is_testing() && !is_snapshot(). case, want avoid run-time dependency testthat, case just copy implementation functions utils.R similar.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_testing.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine testing status — is_testing","text":"","code":"is_testing() is_parallel() is_checking() is_snapshot() testing_package()"},{"path":"https://testthat.r-lib.org/dev/reference/local_edition.html","id":null,"dir":"Reference","previous_headings":"","what":"Temporarily change the active testthat edition — local_edition","title":"Temporarily change the active testthat edition — local_edition","text":"local_edition() allows temporarily (within single test single test file) change active edition testthat. edition_get() allows retrieve currently active edition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_edition.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Temporarily change the active testthat edition — local_edition","text":"","code":"local_edition(x, .env = parent.frame()) edition_get()"},{"path":"https://testthat.r-lib.org/dev/reference/local_edition.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Temporarily change the active testthat edition — local_edition","text":"x Edition single integer. .env Environment controls scope changes. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":null,"dir":"Reference","previous_headings":"","what":"Mocking tools — local_mocked_bindings","title":"Mocking tools — local_mocked_bindings","text":"with_mocked_bindings() local_mocked_bindings() provide tools \"mocking\", temporarily redefining function behaves differently tests. helpful testing functions depend external state (.e. reading value file website, pretending package installed). functions represent second attempt bringing mocking testthat, incorporating learned mockr, mockery, mockthat packages.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Mocking tools — local_mocked_bindings","text":"","code":"local_mocked_bindings(..., .package = NULL, .env = caller_env()) with_mocked_bindings(code, ..., .package = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Mocking tools — local_mocked_bindings","text":"... Name-value pairs providing functions mock. .package name package mocked functions inserted. Generally, supply automatically detected whole package tests run one package active development (.e. loaded pkgload::load_all()). recommend using mock functions packages, modify namespaces . .env Environment defines effect scope. expert use . code Code execute specified bindings.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"use","dir":"Reference","previous_headings":"","what":"Use","title":"Mocking tools — local_mocked_bindings","text":"four places function trying mock might come : Internal package. Imported external package via NAMESPACE. base environment. Called external package ::. described turn .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"internal-amp-imported-functions","dir":"Reference","previous_headings":"","what":"Internal & imported functions","title":"Mocking tools — local_mocked_bindings","text":"mock internal imported functions way. example, take code: matter whether another_function() defined package imported dependency @import @importFrom, mock way:","code":"some_function <- function() { another_function() } local_mocked_bindings( another_function = function(...) \"new_value\" )"},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"base-functions","dir":"Reference","previous_headings":"","what":"Base functions","title":"Mocking tools — local_mocked_bindings","text":"mock function base package, need make sure binding function package. easiest binding value NULL. example, wanted mock interactive() package, need include code somewhere package: necessary? with_mocked_bindings() local_mocked_bindings() work temporarily modifying bindings within package's namespace. tests running inside R CMD check namespace locked means possible create new bindings need make sure binding exists already.","code":"interactive <- NULL"},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"namespaced-calls","dir":"Reference","previous_headings":"","what":"Namespaced calls","title":"Mocking tools — local_mocked_bindings","text":"trickier mock functions packages call ::. example, take minor variation: mock function, need modify another_function() inside anotherpackage package. can supplying .package argument local_mocked_bindings() recommend affect calls anotherpackage::another_function(), just calls originating package. Instead, safer either import function package, make wrapper can mock:","code":"some_function <- function() { anotherpackage::another_function() } some_function <- function() { my_wrapper() } my_wrapper <- function(...) { anotherpackage::another_function(...) } local_mocked_bindings( my_wrapper = function(...) \"new_value\" )"},{"path":"https://testthat.r-lib.org/dev/reference/local_snapshotter.html","id":null,"dir":"Reference","previous_headings":"","what":"Instantiate local snapshotting context — local_snapshotter","title":"Instantiate local snapshotting context — local_snapshotter","text":"Needed want run snapshot tests outside usual testthat framework expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_snapshotter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Instantiate local snapshotting context — local_snapshotter","text":"","code":"local_snapshotter( snap_dir = NULL, cleanup = FALSE, fail_on_new = FALSE, .env = parent.frame() )"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":null,"dir":"Reference","previous_headings":"","what":"Locally set options for maximal test reproducibility — local_test_context","title":"Locally set options for maximal test reproducibility — local_test_context","text":"local_test_context() run automatically test_that() may want run want replicate test results interactively. run inside function, effects automatically reversed function exits; running global environment, use withr::deferred_run() undo. local_reproducible_output() run automatically test_that() 3rd edition. might want call override default settings inside test, want test Unicode, coloured output, non-standard width.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Locally set options for maximal test reproducibility — local_test_context","text":"","code":"local_test_context(.env = parent.frame()) local_reproducible_output( width = 80, crayon = FALSE, unicode = FALSE, rstudio = FALSE, hyperlinks = FALSE, lang = \"en\", .env = parent.frame() )"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Locally set options for maximal test reproducibility — local_test_context","text":".env Environment use scoping; expert use . width Value \"width\" option. crayon Determines whether crayon (now cli) colour applied. unicode Value \"cli.unicode\" option. test skipped l10n_info()$`UTF-8` FALSE. rstudio pretend inside RStudio? hyperlinks use ANSI hyperlinks. lang Optionally, supply BCP47 language code set language used translating error messages. lower case two letter ISO 639 country code, optionally followed \"_\" \"-\" upper case two letter ISO 3166 region code.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Locally set options for maximal test reproducibility — local_test_context","text":"local_test_context() sets TESTTHAT = \"true\", ensures is_testing() returns TRUE allows code tell run testthat. third edition, local_test_context() also calls local_reproducible_output() temporary sets following options: cli.dynamic = FALSE tests assume run dynamic console (.e. one can move cursor around). cli.unicode (default: FALSE) cli package never generates unicode output (normally cli uses unicode Linux/Mac Windows). Windows easily save unicode output disk, must set false consistency. cli.condition_width = Inf new lines introduced width-wrapping condition messages interfere message matching. crayon.enabled (default: FALSE) suppresses ANSI colours generated cli crayon packages (normally colours used cli detects terminal supports colour). cli.num_colors (default: 1L) crayon option. lifecycle_verbosity = \"warning\" every lifecycle problem always generates warning (otherwise deprecated functions generate warning every time). max.print = 99999 number values printed. OutDec = \".\" numbers always uses . decimal point (European users sometimes set OutDec = \",\"). rlang_interactive = FALSE rlang::is_interactive() returns FALSE, code uses pretends non-interactive environment. useFancyQuotes = FALSE base R functions always use regular (straight) quotes (otherwise default locale dependent, see sQuote() details). width (default: 80) control width printed output (usually varies size console). modifies following env vars: Unsets RSTUDIO, ensures RStudio never detected running. Sets LANGUAGE = \"en\", ensures message translation occurs. Finally, sets collation locale \"C\", ensures character sorting regardless system locale.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Locally set options for maximal test reproducibility — local_test_context","text":"","code":"local({ local_test_context() cat(cli::col_blue(\"Text will not be colored\")) cat(cli::symbol$ellipsis) cat(\"\\n\") }) #> Text will not be colored... test_that(\"test ellipsis\", { local_reproducible_output(unicode = FALSE) expect_equal(cli::symbol$ellipsis, \"...\") local_reproducible_output(unicode = TRUE) expect_equal(cli::symbol$ellipsis, \"\\u2026\") }) #> Test passed"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_directory.html","id":null,"dir":"Reference","previous_headings":"","what":"Locally set test directory options — local_test_directory","title":"Locally set test directory options — local_test_directory","text":"expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_directory.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Locally set test directory options — local_test_directory","text":"","code":"local_test_directory(path, package = NULL, .env = parent.frame())"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_directory.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Locally set test directory options — local_test_directory","text":"path Path directory files package Optional package name, known.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return TRUE or FALSE? — logical-expectations","title":"Does code return TRUE or FALSE? — logical-expectations","text":"fall-back expectations can use none specific expectations apply. disadvantage may get less informative error message.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return TRUE or FALSE? — logical-expectations","text":"","code":"expect_true(object, info = NULL, label = NULL) expect_false(object, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return TRUE or FALSE? — logical-expectations","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Does code return TRUE or FALSE? — logical-expectations","text":"Attributes ignored.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return TRUE or FALSE? — logical-expectations","text":"","code":"expect_true(2 == 2) # Failed expectations will throw an error if (FALSE) { expect_true(2 != 2) } expect_true(!(2 != 2)) # or better: expect_false(2 != 2) a <- 1:3 expect_true(length(a) == 3) # but better to use more specific expectation, if available expect_equal(length(a), 3)"},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":null,"dir":"Reference","previous_headings":"","what":"Make an equality test. — make_expectation","title":"Make an equality test. — make_expectation","text":"convenience function make expectation checks input stays .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make an equality test. — make_expectation","text":"","code":"make_expectation(x, expectation = \"equals\")"},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make an equality test. — make_expectation","text":"x vector values expectation type equality want test (\"equals\", \"is_equivalent_to\", \"is_identical_to\")","code":""},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make an equality test. — make_expectation","text":"","code":"x <- 1:10 make_expectation(x) #> expect_equal(x, 1:10) make_expectation(mtcars$mpg) #> expect_equal(mtcars$mpg, c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, #> 24.4, 22.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, #> 30.4, 33.9, 21.5, 15.5, 15.2, 13.3, 19.2, 27.3, 26, 30.4, 15.8, #> 19.7, 15, 21.4)) df <- data.frame(x = 2) make_expectation(df) #> expect_equal(df, structure(list(x = 2), class = \"data.frame\", row.names = c(NA, #> -1L)))"},{"path":"https://testthat.r-lib.org/dev/reference/not.html","id":null,"dir":"Reference","previous_headings":"","what":"Negate an expectation — not","title":"Negate an expectation — not","text":"negates expectation, making possible express want opposite standard expectation. function deprecated removed future version.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/not.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Negate an expectation — not","text":"","code":"not(f)"},{"path":"https://testthat.r-lib.org/dev/reference/not.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Negate an expectation — not","text":"f existing expectation function","code":""},{"path":"https://testthat.r-lib.org/dev/reference/oldskool.html","id":null,"dir":"Reference","previous_headings":"","what":"Old-style expectations. — oldskool","title":"Old-style expectations. — oldskool","text":"Initial testthat used style testing looked like expect_that(, equals(b))) allowed expectations read like English sentences, verbose bit cutesy. style continue work soft-deprecated - longer documented, new expectations use new style expect_equal(, b).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/oldskool.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Old-style expectations. — oldskool","text":"","code":"is_null() is_a(class) is_true() is_false() has_names(expected, ignore.order = FALSE, ignore.case = FALSE) is_less_than(expected, label = NULL, ...) is_more_than(expected, label = NULL, ...) equals(expected, label = NULL, ...) is_equivalent_to(expected, label = NULL) is_identical_to(expected, label = NULL) equals_reference(file, label = NULL, ...) shows_message(regexp = NULL, all = FALSE, ...) gives_warning(regexp = NULL, all = FALSE, ...) prints_text(regexp = NULL, ...) throws_error(regexp = NULL, ...) matches(regexp, all = TRUE, ...)"},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":null,"dir":"Reference","previous_headings":"","what":"Quasi-labelling — quasi_label","title":"Quasi-labelling — quasi_label","text":"first argument every expect_ function can use unquoting construct better labels. makes easy create informative labels expectations used inside function loop. quasi_label() wraps details, returning expression label.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Quasi-labelling — quasi_label","text":"","code":"quasi_label(quo, label = NULL, arg = \"quo\")"},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Quasi-labelling — quasi_label","text":"quo quosure created rlang::enquo(). label optional label override default. provided internal usage. Modern expectations include label parameter. arg Argument name shown error message quo missing.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Quasi-labelling — quasi_label","text":"list containing two elements: val evaluate value quo lab quasiquoted label generated quo","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"limitations","dir":"Reference","previous_headings":"","what":"Limitations","title":"Quasi-labelling — quasi_label","text":"expect_ function use unquoting generate informative labels, can use unquoting purposes. Instead, need perform unquoting outside expectation test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Quasi-labelling — quasi_label","text":"","code":"f <- function(i) if (i > 3) i * 9 else i * 10 i <- 10 # This sort of expression commonly occurs inside a for loop or function # And the failure isn't helpful because you can't see the value of i # that caused the problem: show_failure(expect_equal(f(i), i * 10)) #> Failed expectation: #> f(i) (`actual`) not equal to i * 10 (`expected`). #> #> `actual`: 90 #> `expected`: 100 # To overcome this issue, testthat allows you to unquote expressions using # !!. This causes the failure message to show the value rather than the # variable name show_failure(expect_equal(f(!!i), !!(i * 10))) #> Failed expectation: #> f(10) (`actual`) not equal to 100 (`expected`). #> #> `actual`: 90 #> `expected`: 100"},{"path":"https://testthat.r-lib.org/dev/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. magrittr %>%","code":""},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":null,"dir":"Reference","previous_headings":"","what":"Get and set active reporter. — reporter-accessors","title":"Get and set active reporter. — reporter-accessors","text":"get_reporter() set_reporter() access modify current \"active\" reporter. Generally, functions called directly; instead use with_reporter() temporarily change, reset, active reporter.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get and set active reporter. — reporter-accessors","text":"","code":"set_reporter(reporter) get_reporter() with_reporter(reporter, code, start_end_reporter = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get and set active reporter. — reporter-accessors","text":"reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. code Code execute. start_end_reporter reporters start_reporter() end_reporter() methods called? expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get and set active reporter. — reporter-accessors","text":"with_reporter() invisible returns reporter active code evaluated.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/run_cpp_tests.html","id":null,"dir":"Reference","previous_headings":"","what":"Do C++ tests past? — expect_cpp_tests_pass","title":"Do C++ tests past? — expect_cpp_tests_pass","text":"Test compiled code package package. call function automatically generated tests/testthat/test-cpp.R calling use_catch(); need manually call expectation .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/run_cpp_tests.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Do C++ tests past? — expect_cpp_tests_pass","text":"","code":"expect_cpp_tests_pass(package) run_cpp_tests(package)"},{"path":"https://testthat.r-lib.org/dev/reference/run_cpp_tests.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Do C++ tests past? — expect_cpp_tests_pass","text":"package name package test.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/set_max_fails.html","id":null,"dir":"Reference","previous_headings":"","what":"Set maximum number of test failures allowed before aborting the run — set_max_fails","title":"Set maximum number of test failures allowed before aborting the run — set_max_fails","text":"sets TESTTHAT_MAX_FAILS env var affect current R process processes launched .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/set_max_fails.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Set maximum number of test failures allowed before aborting the run — set_max_fails","text":"","code":"set_max_fails(n)"},{"path":"https://testthat.r-lib.org/dev/reference/set_max_fails.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Set maximum number of test failures allowed before aborting the run — set_max_fails","text":"n Maximum number failures allowed.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/set_state_inspector.html","id":null,"dir":"Reference","previous_headings":"","what":"State inspected — set_state_inspector","title":"State inspected — set_state_inspector","text":"One pernicious challenges debug test runs fine test suite, fails run interactively (similarly, fails randomly running tests parallel). One common causes problem accidentally changing global state previous test (e.g. changing option, environment variable, working directory). hard debug, hard figure test made change. Luckily testthat provides tool figure tests changing global state. can register state inspector set_state_inspector() testthat run test, store results, report differences. example, wanted see tests changing options environment variables, put code tests/testthat/helper-state.R: (might discover packages outside control changing global state, case might want modify function ignore values.) problems can troublesome resolve CRAN check notes report things like connections left open. can easily debug problem :","code":"set_state_inspector(function() { list( options = options(), envvars = Sys.getenv() ) }) set_state_inspector(function() { getAllConnections() })"},{"path":"https://testthat.r-lib.org/dev/reference/set_state_inspector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"State inspected — set_state_inspector","text":"","code":"set_state_inspector(callback)"},{"path":"https://testthat.r-lib.org/dev/reference/set_state_inspector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"State inspected — set_state_inspector","text":"callback Either zero-argument function returns object capturing global state interested , NULL.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":null,"dir":"Reference","previous_headings":"","what":"Skip a test — skip","title":"Skip a test — skip","text":"skip_if() skip_if_not() allow skip tests, immediately concluding test_that() block without executing expectations. allows skip test without failure, reason run (e.g. depends feature specific operating system, requires specific version package). See vignette(\"skipping\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Skip a test — skip","text":"","code":"skip(message = \"Skipping\") 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, arch = NULL) skip_on_ci() skip_on_covr() skip_on_bioc() skip_if_translated(msgid = \"'%s' not found\")"},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Skip a test — skip","text":"message message describing test skipped. condition Boolean condition check. skip_if_not() skip FALSE, skip_if() skip TRUE. pkg Name package check minimum_version Minimum required version package host string hostname lookup os Character vector one operating systems skip . Supported values \"windows\", \"mac\", \"linux\", \"solaris\". arch Character vector one architectures skip . Common values include \"i386\" (32 bit), \"x86_64\" (64 bit), \"aarch64\" (M1 mac). Supplying arch makes test stricter; .e. os arch must match order test skipped. msgid R message identifier used check translation: default uses message included translation packs. See complete list R-base.pot.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"helpers","dir":"Reference","previous_headings":"","what":"Helpers","title":"Skip a test — skip","text":"skip_if_not_installed(\"pkg\") skips tests package \"pkg\" installed loaded (using requireNamespace()). Generally, can assume suggested packages installed, need check specifically, unless particularly difficult install. skip_if_offline() skips internet connection available (using curl::nslookup()) test run CRAN. Requires curl packages installed. skip_if_translated(\"msg\") skips tests \"msg\" translated. skip_on_bioc() skips Bioconductor (using IS_BIOC_BUILD_MACHINE env var). skip_on_cran() skips CRAN (using NOT_CRAN env var set devtools friends). skip_on_covr() skips covr running (using R_COVR env var). skip_on_ci() skips continuous integration systems like GitHub Actions, travis, appveyor (using CI env var). skip_on_os() skips specified operating system(s) (\"windows\", \"mac\", \"linux\", \"solaris\").","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Skip a test — skip","text":"","code":"if (FALSE) skip(\"Some Important Requirement is not available\") 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 }) #> -- Skip: skip example ---------------------------------------------------------- #> Reason: skip #>"},{"path":"https://testthat.r-lib.org/dev/reference/skip_on_travis.html","id":null,"dir":"Reference","previous_headings":"","what":"Superseded skip functions — skip_on_travis","title":"Superseded skip functions — skip_on_travis","text":"skip_on_travis() skip_on_appveyor() superseded skip_on_ci().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip_on_travis.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Superseded skip functions — skip_on_travis","text":"","code":"skip_on_travis() skip_on_appveyor()"},{"path":"https://testthat.r-lib.org/dev/reference/snapshot_accept.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot management — snapshot_accept","title":"Snapshot management — snapshot_accept","text":"snapshot_accept() accepts modified snapshots. snapshot_review() opens Shiny app shows visual diff modified snapshot. particularly useful whole file snapshots created expect_snapshot_file().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/snapshot_accept.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot management — snapshot_accept","text":"","code":"snapshot_accept(files = NULL, path = \"tests/testthat\") snapshot_review(files = NULL, path = \"tests/testthat\")"},{"path":"https://testthat.r-lib.org/dev/reference/snapshot_accept.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot management — snapshot_accept","text":"files Optionally, filter effects snapshots specified files. can snapshot name (e.g. foo foo.md), snapshot file name (e.g. testfile/foo.txt), snapshot file directory (e.g. testfile/). path Path tests.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/source_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Source a file, directory of files, or various important subsets — source_file","title":"Source a file, directory of files, or various important subsets — source_file","text":"used test_dir() friends","code":""},{"path":"https://testthat.r-lib.org/dev/reference/source_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Source a file, directory of files, or various important subsets — source_file","text":"","code":"source_file( path, env = test_env(), chdir = TRUE, desc = NULL, wrap = TRUE, error_call = caller_env() ) source_dir( path, pattern = \"\\\\.[rR]$\", env = test_env(), chdir = TRUE, wrap = TRUE ) source_test_helpers(path = \"tests/testthat\", env = test_env()) source_test_setup(path = \"tests/testthat\", env = test_env()) source_test_teardown(path = \"tests/testthat\", env = test_env())"},{"path":"https://testthat.r-lib.org/dev/reference/source_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Source a file, directory of files, or various important subsets — source_file","text":"path Path files. env Environment evaluate code. chdir Change working directory dirname(path)? desc -NULL, run test description. wrap Automatically wrap code within test_that()? ensures expectations reported, even outside test block. pattern Regular expression used filter files.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/takes_less_than.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code take less than the expected amount of time to run? — takes_less_than","title":"Does code take less than the expected amount of time to run? — takes_less_than","text":"useful performance regression testing.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/takes_less_than.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code take less than the expected amount of time to run? — takes_less_than","text":"","code":"takes_less_than(amount)"},{"path":"https://testthat.r-lib.org/dev/reference/takes_less_than.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code take less than the expected amount of time to run? — takes_less_than","text":"amount maximum duration seconds","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":null,"dir":"Reference","previous_headings":"","what":"Run code before/after tests — teardown","title":"Run code before/after tests — teardown","text":"longer recommend using setup() teardown(); instead think better practice use test fixture described vignette(\"test-fixtures\"). Code setup() block run immediately clean environment. Code teardown() block run upon completion test file, even exits error. Multiple calls teardown() executed order created.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run code before/after tests — teardown","text":"","code":"teardown(code, env = parent.frame()) setup(code, env = parent.frame())"},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run code before/after tests — teardown","text":"code Code evaluate env Environment code evaluated. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run code before/after tests — teardown","text":"","code":"if (FALSE) { # Old approach tmp <- tempfile() setup(writeLines(\"some test data\", tmp)) teardown(unlink(tmp)) } # Now recommended: local_test_data <- function(env = parent.frame()) { tmp <- tempfile() writeLines(\"some test data\", tmp) withr::defer(unlink(tmp), env) tmp } # Then call local_test_data() in your tests"},{"path":"https://testthat.r-lib.org/dev/reference/teardown_env.html","id":null,"dir":"Reference","previous_headings":"","what":"Run code after all test files — teardown_env","title":"Run code after all test files — teardown_env","text":"environment purpose handle withr::defer(): use want run code tests run. Typically, use withr::defer(cleanup(), teardown_env()) immediately made mess setup-*.R file.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown_env.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run code after all test files — teardown_env","text":"","code":"teardown_env()"},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":null,"dir":"Reference","previous_headings":"","what":"Run all tests in a directory — test_dir","title":"Run all tests in a directory — test_dir","text":"function low-level workhorse powers test_local() test_package(). Generally, call function directly. particular, responsible ensuring functions test available test env (e.g. via load_package). See vignette(\"special-files\") learn conventions test, helper, setup files testthat uses, might use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run all tests in a directory — test_dir","text":"","code":"test_dir( path, filter = NULL, reporter = NULL, env = NULL, ..., load_helpers = TRUE, stop_on_failure = TRUE, stop_on_warning = FALSE, wrap = lifecycle::deprecated(), package = NULL, load_package = c(\"none\", \"installed\", \"source\") )"},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run all tests in a directory — test_dir","text":"path Path directory containing tests. filter NULL, tests file names matching regular expression executed. Matching performed file name stripped \"test-\" \".R\". reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. env Environment execute tests. Expert use . ... Additional arguments passed grepl() control filtering. load_helpers Source helper files running tests? stop_on_failure TRUE, throw error tests fail. stop_on_warning TRUE, throw error tests generate warnings. wrap DEPRECATED package tests belong package, name package. load_package Strategy use load package code: \"none\", default, load package. \"installed\", uses library() load installed package. \"source\", uses pkgload::load_all() source package. configure arguments passed load_all(), add field DESCRIPTION file:","code":"Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run all tests in a directory — test_dir","text":"list (invisibly) containing data test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"environments","dir":"Reference","previous_headings":"","what":"Environments","title":"Run all tests in a directory — test_dir","text":"test run clean environment keep tests isolated possible. package tests, environment inherits package's namespace environment, tests can access internal functions objects.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_env.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate default testing environment. — test_env","title":"Generate default testing environment. — test_env","text":"use new environment inherits globalenv() package namespace. ideal world, avoid putting global environment search path tests, currently possible without losing ability load packages tests.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_env.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate default testing environment. — test_env","text":"","code":"test_env(package = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/test_examples.html","id":null,"dir":"Reference","previous_headings":"","what":"Test package examples — test_examples","title":"Test package examples — test_examples","text":"helper functions make easier test examples package. example counts one test, succeeds code runs without error. Generally, redundant R CMD check, recommended routine practice.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_examples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test package examples — test_examples","text":"","code":"test_examples(path = \"../..\") test_rd(rd, title = attr(rd, \"Rdfile\")) test_example(path, title = path)"},{"path":"https://testthat.r-lib.org/dev/reference/test_examples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test package examples — test_examples","text":"path test_examples(), path directory containing Rd files. test_example(), path single Rd file. Remember working directory tests tests/testthat. rd parsed Rd object, obtained tools::Rd_db() otherwise. title Test title use","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Run tests in a single file — test_file","title":"Run tests in a single file — test_file","text":"Helper, setup, teardown files located directory test also run. See vignette(\"special-files\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run tests in a single file — test_file","text":"","code":"test_file( path, reporter = default_compact_reporter(), desc = NULL, package = NULL, ... )"},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run tests in a single file — test_file","text":"path Path file. reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. desc Optionally, supply string run single test (test_that() describe()) description. package tests belong package, name package. ... Additional parameters passed test_dir()","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run tests in a single file — test_file","text":"list (invisibly) containing data test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"environments","dir":"Reference","previous_headings":"","what":"Environments","title":"Run tests in a single file — test_file","text":"test run clean environment keep tests isolated possible. package tests, environment inherits package's namespace environment, tests can access internal functions objects.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run tests in a single file — test_file","text":"","code":"path <- testthat_example(\"success\") test_file(path) #> #> ══ Testing test-success.R ════════════════════════════════════════════════ #> #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] #> [ FAIL 0 | WARN 0 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 2 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 3 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] #> #> ── Warning (test-success.R:10:3): some tests have warnings ───────────────────── #> NaNs produced #> Backtrace: #> ▆ #> 1. └─testthat::expect_equal(log(-1), NaN) at test-success.R:10:3 #> 2. └─testthat::quasi_label(enquo(object), label, arg = \"object\") #> 3. └─rlang::eval_bare(expr, quo_get_env(quo)) #> #> ── Skipped tests (1) ───────────────────────────────────────────────────── #> • This test hasn't been written yet (1): test-success.R:6:3 #> #> #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] test_file(path, desc = \"some tests have warnings\") #> #> ══ Testing test-success.R ════════════════════════════════════════════════ #> #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 1 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 1 | SKIP 0 | PASS 1 ] #> #> ── Warning (test-success.R:10:3): some tests have warnings ───────────────────── #> NaNs produced #> Backtrace: #> ▆ #> 1. └─testthat::expect_equal(log(-1), NaN) at test-success.R:10:3 #> 2. └─testthat::quasi_label(enquo(object), label, arg = \"object\") #> 3. └─rlang::eval_bare(expr, quo_get_env(quo)) #> #> [ FAIL 0 | WARN 1 | SKIP 0 | PASS 1 ] test_file(path, reporter = \"minimal\") #> .SW..."},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":null,"dir":"Reference","previous_headings":"","what":"Run all tests in a package — test_package","title":"Run all tests in a package — test_package","text":"test_local() tests local source package. test_package() tests installed package. test_check() checks package R CMD check. See vignette(\"special-files\") learn various files testthat works .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run all tests in a package — test_package","text":"","code":"test_package(package, reporter = check_reporter(), ...) test_check(package, reporter = check_reporter(), ...) test_local(path = \".\", reporter = NULL, ..., load_package = \"source\")"},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run all tests in a package — test_package","text":"package tests belong package, name package. reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. ... Additional arguments passed test_dir() path Path directory containing tests. load_package Strategy use load package code: \"none\", default, load package. \"installed\", uses library() load installed package. \"source\", uses pkgload::load_all() source package. configure arguments passed load_all(), add field DESCRIPTION file:","code":"Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run all tests in a package — test_package","text":"list (invisibly) containing data test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"r-cmd-check","dir":"Reference","previous_headings":"","what":"R CMD check","title":"Run all tests in a package — test_package","text":"run testthat automatically R CMD check, make sure tests/testthat.R contains:","code":"library(testthat) library(yourpackage) test_check(\"yourpackage\")"},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"environments","dir":"Reference","previous_headings":"","what":"Environments","title":"Run all tests in a package — test_package","text":"test run clean environment keep tests isolated possible. package tests, environment inherits package's namespace environment, tests can access internal functions objects.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":null,"dir":"Reference","previous_headings":"","what":"Locate a file in the testing directory — test_path","title":"Locate a file in the testing directory — test_path","text":"Many tests require external file (e.g. .csv testing data import function) working directory varies depending way running test (e.g. interactively, devtools::test(), R CMD check). test_path() understands variations automatically generates path relative tests/testthat, regardless directory might reside relative current working directory.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Locate a file in the testing directory — test_path","text":"","code":"test_path(...)"},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Locate a file in the testing directory — test_path","text":"... Character vectors giving path components.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Locate a file in the testing directory — test_path","text":"character vector giving path.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Locate a file in the testing directory — test_path","text":"","code":"if (FALSE) { test_path(\"foo.csv\") test_path(\"data\", \"foo.csv\") }"},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":null,"dir":"Reference","previous_headings":"","what":"Run a test — test_that","title":"Run a test — test_that","text":"test encapsulates series expectations small, self-contained unit functionality. test contains one expectations, expect_equal() expect_error(), lives test/testhat/test* file, often together tests relate function set functions. test execution environment, object created test also dies test. Note cleanup happen automatically aspects global state, session options filesystem changes. Avoid changing global state, possible, reverse changes make.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run a test — test_that","text":"","code":"test_that(desc, code)"},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run a test — test_that","text":"desc Test name. Names brief, evocative. common write description reads like natural sentence, e.g. test_that(\"multiplication works\", { ... }). code Test code containing expectations. Braces ({}) always used order get accurate location data test failures.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run a test — test_that","text":"run interactively, returns invisible(TRUE) tests pass, otherwise throws error.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run a test — test_that","text":"","code":"test_that(\"trigonometric functions match identities\", { expect_equal(sin(pi / 4), 1 / sqrt(2)) expect_equal(cos(pi / 4), 1 / sqrt(2)) expect_equal(tan(pi / 4), 1) }) #> Test passed if (FALSE) { test_that(\"trigonometric functions match identities\", { expect_equal(sin(pi / 4), 1) }) }"},{"path":"https://testthat.r-lib.org/dev/reference/testthat-package.html","id":null,"dir":"Reference","previous_headings":"","what":"An R package to make testing fun! — testthat-package","title":"An R package to make testing fun! — testthat-package","text":"Try example . look references learn function documentation test_that().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat-package.html","id":"options","dir":"Reference","previous_headings":"","what":"Options","title":"An R package to make testing fun! — testthat-package","text":"testthat.use_colours: output coloured? (Default: TRUE). testthat.summary.max_reports: maximum number detailed test reports printed summary reporter (default: 10). testthat.summary.omit_dots: Omit progress dots summary reporter (default: FALSE).","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/testthat-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"An R package to make testing fun! — testthat-package","text":"Maintainer: Hadley Wickham hadley@posit.co contributors: Posit Software, PBC [copyright holder, funder] R Core team (Implementation utils::recover()) [contributor]","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve paths to built-in example test files — testthat_examples","title":"Retrieve paths to built-in example test files — testthat_examples","text":"testthat_examples() retrieves path directory test files, testthat_example() retrieves path single test file.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve paths to built-in example test files — testthat_examples","text":"","code":"testthat_examples() testthat_example(filename)"},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Retrieve paths to built-in example test files — testthat_examples","text":"filename Name test file","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Retrieve paths to built-in example test files — testthat_examples","text":"","code":"dir(testthat_examples()) #> [1] \"_snaps\" \"test-failure.R\" \"test-success.R\" testthat_example(\"success\") #> [1] \"/home/runner/work/_temp/Library/testthat/examples/test-success.R\""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"Create testthat_results object test results stored ListReporter results field.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"","code":"testthat_results(results)"},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"results list stored ListReporter","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"list argument testthat_results object","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/testthat_tolerance.html","id":null,"dir":"Reference","previous_headings":"","what":"Default numeric tolerance — testthat_tolerance","title":"Default numeric tolerance — testthat_tolerance","text":"testthat's default numeric tolerance 1.4901161 × 10-8.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_tolerance.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default numeric tolerance — testthat_tolerance","text":"","code":"testthat_tolerance()"},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":null,"dir":"Reference","previous_headings":"","what":"Try evaluating an expressing multiple times until it succeeds. — try_again","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"Try evaluating expressing multiple times succeeds.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"","code":"try_again(times, code)"},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"times Maximum number attempts. code Code evaluate","code":""},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"","code":"third_try <- local({ i <- 3 function() { i <<- i - 1 if (i > 0) fail(paste0(\"i is \", i)) } }) try_again(3, third_try())"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":null,"dir":"Reference","previous_headings":"","what":"Use Catch for C++ Unit Testing — use_catch","title":"Use Catch for C++ Unit Testing — use_catch","text":"Add necessary infrastructure enable C++ unit testing R packages Catch testthat.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Use Catch for C++ Unit Testing — use_catch","text":"","code":"use_catch(dir = getwd())"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Use Catch for C++ Unit Testing — use_catch","text":"dir directory containing R package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Use Catch for C++ Unit Testing — use_catch","text":"Calling use_catch() : Create file src/test-runner.cpp, ensures testthat package understand run package's unit tests, Create example test file src/test-example.cpp, showcases might use Catch write unit test, Add test file tests/testthat/test-cpp.R, ensures testthat run compiled tests invocations devtools::test() R CMD check, Create file R/catch-routine-registration.R, ensures R automatically register routine tools::package_native_routine_registration_skeleton() invoked. also need : Add xml2 Suggests, e.g. usethis::use_package(\"xml2\", \"Suggests\") Add testthat LinkingTo, e.g. usethis::use_package(\"testthat\", \"LinkingTo\") C++ unit tests can added C++ source files within src directory package, format similar R code tested testthat. simple example unit test written testthat + Catch: package compiled, unit tests alongside harness running tests compiled R package, C entry point run_testthat_tests(). testthat use entry point run unit tests detected.","code":"context(\"C++ Unit Test\") { test_that(\"two plus two is four\") { int result = 2 + 2; expect_true(result == 4); } }"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Use Catch for C++ Unit Testing — use_catch","text":"functions provided Catch available CATCH_ prefix -- see full list. testthat provides following wrappers, conform testthat's R interface: general, prefer using testthat wrappers, testthat also work ensure unit tests within compiled run using Solaris Studio compilers (currently unsupported Catch). make easier submit packages CRAN use Catch.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"symbol-registration","dir":"Reference","previous_headings":"","what":"Symbol Registration","title":"Use Catch for C++ Unit Testing — use_catch","text":"opted disable dynamic symbol lookup package, need explicitly export symbol package testthat can use run unit tests. testthat look routine one names: See Controlling Visibility Registering Symbols Writing R Extensions manual information.","code":"C_run_testthat_tests c_run_testthat_tests run_testthat_tests"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"advanced-usage","dir":"Reference","previous_headings":"","what":"Advanced Usage","title":"Use Catch for C++ Unit Testing — use_catch","text":"like write Catch test runner, can instead use testthat::catchSession() object file form: can useful like run unit tests custom arguments passed Catch session.","code":"#define TESTTHAT_TEST_RUNNER #include void run() { Catch::Session& session = testthat::catchSession(); // interact with the session object as desired }"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"standalone-usage","dir":"Reference","previous_headings":"","what":"Standalone Usage","title":"Use Catch for C++ Unit Testing — use_catch","text":"like use C++ unit testing facilities provided Catch, prefer use regular testthat R testing infrastructure, can manually run unit tests inserting call : necessary within unit test suite.","code":".Call(\"run_testthat_tests\", PACKAGE = )"},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Verify output — verify_output","title":"Verify output — verify_output","text":"function superseded favour expect_snapshot() friends. regression test records interwoven code output file, similar way knitting .Rmd file (see caveats ). verify_output() designed particularly testing print methods error messages, primary goal ensure output helpful human. Obviously, test code, best can make results explicit saving text file. makes output easy verify code reviews, ensures change output accident. verify_output() designed used git: see changed previous run, need use git diff similar.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Verify output — verify_output","text":"","code":"verify_output( path, code, width = 80, crayon = FALSE, unicode = FALSE, env = caller_env() )"},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Verify output — verify_output","text":"path Path record results. usually call test_path() order ensure path used run interactively (working directory typically project root), run automated test (working directory tests/testthat). code Code execute. usually multiline expression contained within {} (similarly test_that() calls). width Width console output crayon Enable cli/crayon package colouring? unicode Enable cli package UTF-8 symbols? set TRUE, call skip_if(!cli::is_utf8_output()) disable test CI platforms support UTF-8 (e.g. Windows). env environment evaluate code .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"syntax","dir":"Reference","previous_headings":"","what":"Syntax","title":"Verify output — verify_output","text":"verify_output() can capture abstract syntax tree, losing whitespace comments. mildly offset limitation: Strings converted R comments output. Strings starting # converted headers output.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"cran","dir":"Reference","previous_headings":"","what":"CRAN","title":"Verify output — verify_output","text":"CRAN, verify_output() never fail, even output changes. avoids false positives tests print methods error messages often fragile due implicit dependencies packages, failure imply incorrect computation, just change presentation.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":null,"dir":"Reference","previous_headings":"","what":"Watch a directory for changes (additions, deletions & modifications). — watch","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"used power auto_test() auto_test_package() functions used rerun tests whenever source code changes.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"","code":"watch(path, callback, pattern = NULL, hash = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"path character vector paths watch. Omit trailing backslash. callback function called everytime change occurs. three parameters: added, deleted, modified, return TRUE keep watching, FALSE stop. pattern file pattern passed dir() hash hashes accurate detecting changes, slower large files. FALSE, uses modification time stamps","code":""},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"Use Ctrl + break (windows), Esc (mac gui) Ctrl + C (command line) stop watcher.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":null,"dir":"Reference","previous_headings":"","what":"Mock functions in a package. — with_mock","title":"Mock functions in a package. — with_mock","text":"with_mock() local_mock() superseded favour with_mocked_bindings() local_mocked_bindings(). works using C code temporarily modify mocked function place. abusive R's internals, makes dangerous, longer recommended.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Mock functions in a package. — with_mock","text":"","code":"with_mock(..., .env = topenv()) local_mock(..., .env = topenv(), .local_envir = parent.frame())"},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Mock functions in a package. — with_mock","text":"... named parameters redefine mocked functions, unnamed parameters evaluated mocking functions .env environment patch functions, defaults top-level environment. character interpreted package name. .local_envir Environment add exit handler. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Mock functions in a package. — with_mock","text":"result last unnamed parameter","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Mock functions in a package. — with_mock","text":"with_mock() local_mock() deprecated third edition.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-development-version","dir":"Changelog","previous_headings":"","what":"testthat (development version)","title":"testthat (development version)","text":"test_file(desc = ) now find describe() tests well testthat() tests (#1903). JunitReporter() now uses ensures numeric values saved xml file . decimal separator. (@maksymiuks, #1660)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-320","dir":"Changelog","previous_headings":"","what":"testthat 3.2.0","title":"testthat 3.2.0","text":"CRAN release: 2023-10-06","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"lifecycle-changes-3-2-0","dir":"Changelog","previous_headings":"","what":"Lifecycle changes","title":"testthat 3.2.0","text":"is_informative_error() wrap argument test_dir() friends now defunct. expect_no_error(), expect_no_warning(), expect_no_message(), expect_no_condition(), local_mocked_bindings(), with_mocked_bindings() now stable, experimental.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-features-3-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"testthat 3.2.0","text":"packages, regardless whether use rlang 1.0.0, now use new snapshot display errors, warnings, messages (#1856). longer shows class name, instead focussing display closely mimics ’ll see interactively, including showing error call. testthat uses improved algorithm finding srcref associated expectation/error/warning/skip. now looks recent call known source found inside test_that() call. generally gives specific locations previous approach gives much better locations error occurs exit handler.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-features-and-bug-fixes-3-2-0","dir":"Changelog","previous_headings":"","what":"Minor features and bug fixes","title":"testthat 3.2.0","text":"Helpers longer run twice. expect_setequal() correctly displays results one actual expected missing elements (#1835). expect_snapshot() friends longer create temporary file every invocation. expect_snapshot_file() now generates clickable links review changes (#1821). expect_snapshot_value() improved error object can’t safely serialized using specified style (#1771). options(rlang_interactive = TRUE) longer causes skip_on_cran() run CRAN (#1868). skip_if_offline() now errors don’t curl installed (#1854). StopReporter gains ability suppress praise test passes. ProgressReporter now uses two characters wide skip column order consistent width 10 tests skipped single file (@mgirlich, #1844). test_file() gains desc argument allows run single test file (#1776).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-3110","dir":"Changelog","previous_headings":"","what":"testthat 3.1.10","title":"testthat 3.1.10","text":"CRAN release: 2023-07-06 Fix upcoming R-devel release. testthat now sets _R_CHECK_BROWSER_NONINTERACTIVE_ environment variable running tests. ensure left-browser() statements trigger error encountered running tests. functionality enabled R (>= 4.3.0). (#1825)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-319","dir":"Changelog","previous_headings":"","what":"testthat 3.1.9","title":"testthat 3.1.9","text":"CRAN release: 2023-06-15 New expect_contains() expect_in() works similarly expect_true((expected %% object)) expect_true((object %% expected)) give informative failure messages (#1346). New is_snapshot() returns TRUE code running inside snapshot test (#1796) is_checking() returns TRUE test running inside R CMD check (#1795) ProgressReporter reports run time test files take longer 1s, rather 0.1s. (#1806) re-displays failures end results. Skips now shown end reporter summaries, tests run. makes less intrusive interactive tests still allowing verify correct tests skipped (#1801). using parallel tests, links failed tests (#1787) links accept/review snapshot (#1802) now work. set_state_inspector() allows register function ’s called every test, reporting differences. useful detecting tests made changes global state (like options, env vars, connections) (#1674). function inspired renv’s testing infrastructure. skip_on_cran() longer skips (errors) run interactively. teardown_env() works cases. testthat longer truncates tracebacks uses rlang’s default tree display.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-318","dir":"Changelog","previous_headings":"","what":"testthat 3.1.8","title":"testthat 3.1.8","text":"CRAN release: 2023-05-04 expect_snapshot() differences longer use quotes. expect_error(), expect_warning(), expect_message() now correctly enforce condition expected base class (e.g. error, warning, message) even class argument used (#1168). () now calls local_test_context() behaves similarly test_that() (#1731), now exported can easily run BDD tests interactively (#1587) skip_on_bioc() now uses documented environment variable (IS_BIOC_BUILD_MACHINE) (#1712). source_file(), used various parts helper setup/teardown machinery, now reports file name case errors (#1704). test_path() now works called within helper files (#1562). New vignette(\"special-files\") describes various special files testthat uses (#1638). with_mocked_bindings() local_mocked_bindings() now also bind imports namespace can mock S3 methods. changes make good substitutes deprecated functions with_mock() local_mock(), older functions now recommend switching newer equivalents instead using mockr mockery packages.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-317","dir":"Changelog","previous_headings":"","what":"testthat 3.1.7","title":"testthat 3.1.7","text":"CRAN release: 2023-03-12 expect_setequal() gives actionable feedback (#1657). expect_snapshot() longer elides new lines run interactively (#1726). Experimental new with_mocked_bindings() local_mocked_bindings() (#1739).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-316","dir":"Changelog","previous_headings":"","what":"testthat 3.1.6","title":"testthat 3.1.6","text":"CRAN release: 2022-12-09 embedded version Catch longer uses sprintf().","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-315","dir":"Changelog","previous_headings":"","what":"testthat 3.1.5","title":"testthat 3.1.5","text":"CRAN release: 2022-10-08 Deprecation warnings longer captured expect_warning(code, NA), expect_no_warning(code), expect_silent(code). ensures bubble top level can address (#1680). want assert code throw deprecation warning, use expect_no_condition(code(), class = \"lifecycle_warning_deprecation\"). New experimental expect_no_error(), expect_no_warning(), expect_no_message(), expect_no_condition() asserting code runs without error, warning, message, condition (#1679). Fixed warning R >=4.2.0 Windows occurred using C++ testing infrastructure testthat provides (#1672). Fixed issue prevent compilation Catch unit tests LLVM 15. interim, packages needing local workaround can set PKG_CPPFLAGS = -DCATCH_CONFIG_CPP11_NO_SHUFFLE src/Makevars. (2, #1687) Improve way capture_output() handles encoding thanks suggestion Kurt Hornik (#1693). means snapshots using UTF-8 encoded text windows work . local_reproducible_output() longer attempt set local language LANG='C' set R version used compiled natural language support (NLS), previously emit non-test-related warnings testing (@dgkf, #1662; @heavywatal, #1689). test_check() now suppresses hyperlinks since ’ll take wrong places (#1648). New set_max_fails() helper make easier set maximum number failures stopping test suite. advice set Inf now clickable (#1628). can now configure behaviour implicit devtools::load_all() call performed devtools::test() package DESCRIPTION file (#1636). disable exports internal functions testthat helpers, use: Helpers now attached search path default calling devtools::test().","code":"Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-314","dir":"Changelog","previous_headings":"","what":"testthat 3.1.4","title":"testthat 3.1.4","text":"CRAN release: 2022-04-26 Minor tweaks output latest cli (#1606).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-313","dir":"Changelog","previous_headings":"","what":"testthat 3.1.3","title":"testthat 3.1.3","text":"CRAN release: 2022-03-29 Package explicitly depend rlang description file now opting new snapshot display errors, warnings, messages. Previously concerned packages explicitly depended rlang >= 1.0.0. display eventually become default packages. Changes include: Condition classes longer included snapshot default. avoid snapshot noise upstream code adds changes class. instance, r-devel added classes base errors. Warnings errors now printed rlang, including call field. makes easy monitor full appearance warning error messages displayed users. change part push towards mentioning useful context error part messages, see release notes rlang 1.0.0 . Test results show hyperlinks failed expectation supported (#1544).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-312","dir":"Changelog","previous_headings":"","what":"testthat 3.1.2","title":"testthat 3.1.2","text":"CRAN release: 2022-01-20 testthat now uses brio reading writing (#1120). ensures snapshots always use “” separate lines (#1516). expect_snapshot() longer inadvertently trims trailing new lines errors messages (#1509). expect_snapshot() generates snapshot different value still compares equal (e.g. ’ve set numeric tolerance), saved values longer update another snapshot file changes. expect_snapshot() now adds .new file variants actually changed, variants, expect_snapshot_file() variant longer immediately deletes .new files (#1468). expect_snapshot_file() gains transform argument match expect_snapshot() (#1474). compare now defaults NULL, automatically guessing comparison type based extension. expect_snapshot_file() now errors file snapshot exist; SnapshotReporter also now treats file directory absolute path (#1476, @malcolmbarrett) New expect_snapshot_warning() match expect_snapshot_error() (#1532). JUnitReporter now includes skip messages/reasons (@rfineman, #1507) local_reproducible_output() gains lang argument can optionally override language used translate error messages (#1483). also sets global option cli.num_colors addition crayon.enabled. test_that() longer inappropriately skips calling expect_equal() ’ve temporarily set locale non-UTF-8 (#1285). skip_if_offline() now automatically calls skip_on_cran() (#1479). snapshot_accept() snapshot_review() now work exactly file specification can snapshot name, file name, directory (#1546). work better variants (#1508). Snapshot cleanup also removes empty directories (#1457). snapshot changes hint also mentions can use snapshot_review() (#1500, @DanChaltiel) message tells variant active (#1540). JUnit reporter now includes skip messages/reasons (@rfineman, #1507).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-311","dir":"Changelog","previous_headings":"","what":"testthat 3.1.1","title":"testthat 3.1.1","text":"CRAN release: 2021-12-03 Condition expectations like expect_error() now match across ancestry chained errors (#1493). can disable setting new inherit argument FALSE. Added preliminary support rlang 1.0 errors. disabled default time . activate , specify rlang (>= 1.0.0) DESCRIPTION file (>= 0.99.0.9001 ’re using dev version). activated, snapshots now use rlang print error warning messages, including Error: Warning: prefixes. means call field conditions now displayed snapshots present. Parent error messages also displayed. Following change, snapshots including error warning messages need revalidated. enable new rlang 1.0 output unconditionally future release. expect_snapshot() gains new argument cnd_class control whether show class errors, warnings, messages. default currently unchanged condition classes keep included snapshots. However, plan change default FALSE upcoming release prevent distracting snapshot diffing upstream packages add error classes. instance, development version R currently adding classes basic errors, causes spurious snapshot changes testing R-devel CI. depend rlang 1.0 (see ), default already set FALSE. expect_snapshot() longer processes rlang injection operators like !!. Fixed bug expectations long inputs use :: (#1472).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-310","dir":"Changelog","previous_headings":"","what":"testthat 3.1.0","title":"testthat 3.1.0","text":"CRAN release: 2021-10-04","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"snapshot-tests-3-1-0","dir":"Changelog","previous_headings":"","what":"Snapshot tests","title":"testthat 3.1.0","text":"expect_snapshot() longer experimental. expect_snapshot() friends gets experimental new variant argument causes snapshot saved _snaps/{variant}/{test}.md instead _snaps/{test}.md. allows generate (compare) unique snapshots different scenarios like operating system R version (#1143). expect_snapshot() gains transform argument, function takes character vector lines returns modified character vector lines. makes easy remove sensitive (e.g. API keys) stochastic (e.g. random temporary directory names) snapshot output (#1345). expect_snapshot_file() now replaces previous .new snapshot code fails different value. expect_snapshot_value() now explicit tolerance argument uses testthat default, thus making like expect_equal() rather expect_identical(). Set NULL want precise comparisons (#1309). expect_snapshot_value(style = \"deparse\") now works negative values (#1342). test containing multiple snapshots fails (skips) snapshots, later snapshots now silently restored. (Previously warned reset snapshots, just later snapshots). multiple tests name use snapshots (good idea), longer get warning. Instead snapshots aggregated across tests.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"breaking-changes-3-1-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"testthat 3.1.0","text":"Condition expectations now consistently return expected condition instead return value (#1371). Previously, return condition return value NULL, leading inconsistent behaviour. breaking change 3rd edition. previously : must now use condition expectations outside: breaking change makes testthat consistent. also makes possible inspect value warning, otherwise require additional tools.","code":"expect_equal(expect_warning(f(), \"warning\"), \"value\") expect_warning(expect_equal(f(), \"value\"), \"warning\") # Equivalently, save the value before inspection expect_warning(value <- f(), \"warning\") expect_equal(value, \"value\")"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-3-1-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 3.1.0","text":"Errors test blocks now display call stored condition object (#1418). Uncaught errors now show class (#1426). Multi-line skips show first line skip summary. expr_label(), used concisely describe expressions used expectations, now better job summarising infix function (#1442). local_reproducible_output() now sets max.print option 99999 (default), tests unaffected changes might’ve made .Rprofile (1367). ProgressReporter (default ) now stops end file; ensures see results related tests, ensures snapshots handled consistently (#1402). ProgressReporter now uses env var adjust maximum number failures. makes easier adjust tests run subprocess, common using RStudio (#1450). skip_on_os() gains arch argument can also choose skip selected architectures (#1421). test_that() now correctly errors expectation fails run interactively (#1430). test_that() now automatically correctly generate “empty test” skip generates warnings messages (doesn’t contain expectations). testthat_tolerance() longer unused argument.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-304","dir":"Changelog","previous_headings":"","what":"testthat 3.0.4","title":"testthat 3.0.4","text":"CRAN release: 2021-07-01 vendored Catch code used use_catch() now uses constant value stack size rather relying SIGSTKSZ. fixes compatibility recent glibc versions SIGSTKSZ longer constant. Fixed issue caused errors early termination tests R <= 3.6 failing condition expectation signalled inside snapshot.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-303","dir":"Changelog","previous_headings":"","what":"testthat 3.0.3","title":"testthat 3.0.3","text":"CRAN release: 2021-06-16 expect_snapshot_file() gains compare argument (#1378, @nbenn). customisation point compare old new snapshot files. functions compare_file_binary() compare_file_text() now exported testthat supplied compare argument. implement behaviour old binary argument now deprecated. expect_snapshot() longer deletes snapshots unexpected error occurs. New announce_snapshot_file() function developers testthat extensions. Announcing snapshot file allows testthat preserve files generated unexpected error skip() (#1393). Unannounced files automatically deleted cleanup generating code isn’t called. New expectation: expect_no_match(). complements expect_match() checking string doesn’t match regular expression (@michaelquinn32, #1381). Support setting testthat edition via environment variable (TESTTHAT_EDITION) well (@michaelquinn32, #1386).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-302","dir":"Changelog","previous_headings":"","what":"testthat 3.0.2","title":"testthat 3.0.2","text":"CRAN release: 2021-02-14 Failing expectations now include backtrace ’re called directly within test_that() instead wrapped helper function (#1307). CheckReporter now records warnings CRAN. Otherwise failed CRAN revdep checks tend cluttered warnings (#1300). automatically cleans testthat-problems.rds left previous runs latest run successful (#1314). expect_s3_class() expect_s4_class() can now check object isn’t S3 S4 object supplying NA second argument (#1321). expect_s3_class() expect_s4_class() format class names less confusing way (#1322). expect_snapshot() collapses multiple adjacent headings , , e.g., multiple lines code row, ’ll see one “Code:” heading (#1311).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-301","dir":"Changelog","previous_headings":"","what":"testthat 3.0.1","title":"testthat 3.0.1","text":"CRAN release: 2020-12-17 New testthat.progress.verbose_skips option. Set FALSE stop reporting skips occur; still appear summary (#1209, @krlmlr). CheckReporter results tweaked based experiences running R CMD check many packages. Hopefully now easier see biggest problems (.e. failures errors) still skips warnings available check needed (#1274). now full test name always shown, matter long (#1268). Catch C++ tests longer reported multiple times (#1237) automatically skipped Solaris since Catch supported (#1257). use_catch() makes clear package needs suggest xml2 (#1235). auto_test_package() works (@mbojan, #1211, #1214). expect_snapshot() gains new error argument controls whether error expected. unexpected error thrown, expected error thrown, expect_snapshot() fail (even CRAN) (#1200). expect_snapshot_value(style = \"deparse\") handles common R data structures. expect_snapshot_value() now passes ... waldo::compare() (#1222). expect_snapshot_file() gives hint next steps failure occurs non-interactive environments (help @maelle, #1179). expect_snapshot_*() gives informative hint ’re running tests interactively (#1226). expect_snapshot_*() automatically removes _snaps directory ’s empty (#1180). also warns snapshots discarded tests duplicated names (#1278, @krlmlr). local_reproducible_output() now sets LANGUAGE env var “en”. matches behaviour R CMD check interactive settings (#1213). also now unsets RSTUDIO envvar, instead setting 0 (#1225). RstudioReporter renamed RStudioReporter. skip_if_not() longer appends “TRUE” custom messages (@dpprdan, #1247). test_that() now warns (3e ) code doesn’t braces, since makes hard track source error (#1280, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-300","dir":"Changelog","previous_headings":"","what":"testthat 3.0.0","title":"testthat 3.0.0","text":"CRAN release: 2020-10-31","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"id_3rd-edition-3-0-0","dir":"Changelog","previous_headings":"","what":"3rd edition","title":"testthat 3.0.0","text":"testhat 3.0.0 brings 3rd edition makes number breaking changes order clean interface help use latest recommendations. opt-3rd edition package, set Config/testthat/edition: 3 DESCRIPTION use local_edition(3) individual tests. can retrieve active edition edition_get(). Learn vignette(\"third-edition\"). context() deprecated. expect_identical() expect_equal() use waldo::compare() compare actual expected results. mostly yields much informative output actual expected values different, writing uncovered bugs existing comparison code. expect_error(), expect_warning(), expect_message(), expect_condition() now use underlying logic: capture first condition matches class/regexp allow anything else bubble (#998/#1052). also warn unexpected arguments never used. argument expect_message() expect_warning() now deprecated. never particularly good idea well documented, now superseded new condition capturing behaviour. expect_equivalent(), expect_reference(), expect_is() expect_that() deprecated. Messages longer automatically silenced. Either use suppressMessages() hide unimportant messages, expect_message() catch important messages (#1095). setup() teardown() deprecated favour test fixtures. See vignette(\"test-fixtures\") details. expect_known_output(), expect_known_value(), expect_known_hash(), expect_equal_to_reference() deprecated favour expect_snapshot_output() expect_snapshot_value(). test_that() now sets number options env vars make output reproducible possible (#1044). Many options previously set various places (devtools::test(), test_dir(), test_file(), verify_output()) now centralised. can use code, debugging tests interactively local_test_context(). with_mock() local_mock() deprecated; please use mockr mockery packages instead (#1099).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"snapshot-testing-3-0-0","dir":"Changelog","previous_headings":"","what":"Snapshot testing","title":"testthat 3.0.0","text":"New family snapshot expectations (expect_snapshot(), expect_snapshot_output(), expect_snapshot_error(), expect_snapshot_value()) provide “snapshot” tests, expected results stored separate files test/testthat/_snaps. ’re useful whenever ’s painful store expected results directly test files. expect_snapshot_file() along snapshot_review() help snapshot complex data, initial support text files, images, data frames (#1050). See vignette(\"snapshotting\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-3-0-0","dir":"Changelog","previous_headings":"","what":"Reporters","title":"testthat 3.0.0","text":"CheckReporter (used inside R CMD check) now prints problems (.e. errors, failures, warnings skips; just first 10), lists skips types, records problems machine readable format tests/testthat-problems.rds (#1075). New CompactProgressReporter tweaks output ProgressReporter use single file, devtools::test_file(). can pick different default setting testthat.default_compact_reporter name reporter. ProgressReporter (default reporter) now keeps stack traces errors happen test, making problems substantially easier track (#1004). checks ’ve exceeded maximum number failures (option testthat.progress.max_fails) expectation, rather end file (#967). also gains new random praise options use emoji, lists skipped tests type (#1028). StopReporter adds random praise emoji single test passes (#1094). refined display failures, now using style CompactProgressReporter ProgressReporter. SummaryReporter now records file start, just context start. makes compatible modern style use context() (#1089). reporters now use exactly format reporting location expectation. Warnings now include backtrace, making easier figure came . Catch C++ tests now provide detailed results test. upgrade existing code, re-run testthat::use_catch() (#1008). Many reporters (e.g. check reporter) longer raise error tests fail. Use stop_on_failure argument devtools::test() testthat::test_dir() code relies . Alternatively, use reporter = c(\"check\", \"fail\") e.g. create failing check reporter.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"fixtures-3-0-0","dir":"Changelog","previous_headings":"","what":"Fixtures","title":"testthat 3.0.0","text":"New vignette(\"test-fixtures\") describes test fixtures; .e. temporarily cleanly change global state order test parts code otherwise hard run (#1042). setup() teardown() superseded favour test fixtures. New teardown_env() use withr::defer(). allows run code tests run.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"skips-3-0-0","dir":"Changelog","previous_headings":"","what":"Skips","title":"testthat 3.0.0","text":"New vignette(\"skipping\") gives general information skipping tests, include basics testing skipping helpers (#1060). ProgressReporter() CheckReporter() list number skipped tests reason end reporter. makes easier check ’re skipping wrong tests, particularly CI services (#1028).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"test-running-3-0-0","dir":"Changelog","previous_headings":"","what":"Test running","title":"testthat 3.0.0","text":"test_that() longer triggers error run outside tests; instead produces informative summary failures, errors, warnings, skips occurred inside test. test_that() now errors desc string (#1161). test_file() now runs helper, setup, teardown code, arguments test_dir() (#968). Long deprecated encoding argument removed. test_dir() now defaults stop_on_failure TRUE consistency test_ functions. wrap argument deprecated; ’s clear ever exposed. New test_local() tests local source package directory. ’s equivalent devtools::test() doesn’t require devtools dependencies installed (#1030).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-3-0-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 3.0.0","text":"testthat longer supports tests stored inst/tests. deprecated since testthat 0.11.0 (released 2015). test_package() (previously used running tests R CMD check) fail silently tests found avoid breaking old packages CRAN (#1149). capture_output() verify_output() use new testthat_print() generic. allows control printed representation object specifically tests (.e. usual print method shows data varies way don’t care tests) (#1056). context_start_file() now exported external reporters (#983, #1082). now strips first instance prefix/suffix (#1041, @stufield). expect_error() longer encourages use class. advice removes one type fragility expense creating different type (#1013). expect_known_failure() removed. far can tell ever used testthat, rather fragile. expect_true(), expect_false(), expect_null() now use waldo produce informative failures. verify_output() longer always fails output contains carriage return character (“) (#1048). uses pdf() device instead png() works systems without X11 (#1011). uses waldo::compare() give informative failures.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-232","dir":"Changelog","previous_headings":"","what":"testthat 2.3.2","title":"testthat 2.3.2","text":"CRAN release: 2020-03-02 Fix R CMD check issues","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-231","dir":"Changelog","previous_headings":"","what":"testthat 2.3.1","title":"testthat 2.3.1","text":"CRAN release: 2019-12-01 last version testthat introduced performance regression error assertions (#963). fix , need install rlang 0.4.2. Fixed error assertions rJava errors (#964). Fixed issue error warning messages retrieved conditionMessage() certain circumstances.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-230","dir":"Changelog","previous_headings":"","what":"testthat 2.3.0","title":"testthat 2.3.0","text":"CRAN release: 2019-11-05","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"conditions-2-3-0","dir":"Changelog","previous_headings":"","what":"Conditions","title":"testthat 2.3.0","text":"release mostly focusses overhaul testthat works conditions (.e. errors, warnings messages). relatively user-facing changes, although now see informative backtraces errors failures. Unexpected errors now printed simplified backtrace. expect_error() expect_condition() now display backtrace error doesn’t conform expectations (#729). expect_error(), expect_warning() expect_message() now call conditionMessage() get condition message. generic makes possible generate messages print-time rather signal-time. expect_error() gets better warning message test custom error class regexp. New exp_signal() function condition signaller implements testthat protocol (signal stop() expectation broken, continue_test restart). Existence restarts first checked invocation. makes possible signal warnings messages different condition signaller (#874). ListReporter now tracks expectations errors, even occur outside tests. ensures stop_on_failure matches results displayed reporter (#936). can silence warnings untested error classes implementing method is_uninformative_warning(). method lazily registered, e.g. vctrs::s3_register(). useful introducing experimental error class without encouraging users depend class tests. Respect options(warn = -1) ignore warnings (@jeroen #958).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"expectations-2-3-0","dir":"Changelog","previous_headings":"","what":"Expectations","title":"testthat 2.3.0","text":"Expectations can now explicitly subclassed new_expectation(). constructor follows new conventions S3 classes takes optional subclass optional attributes. Unquoted inputs longer potentially generate multiple test messages (#929). verify_output() longer uses quasiquotation, fixes issues verifying output tidy eval functions (#945). verify_output() gains unicode parameter turn use Unicode characters cli package. disabled default prevent tests failing platforms like Windows don’t support UTF-8 (contributors’ CI machines). verify_output() now correctly handles multi-line condition messages. verify_output() now adds spacing condition messages, consistent spacing added normal output. verify_output() new syntax inserting headers output files: insert \"# Header\" string (starting # Markdown) add header set outputs.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-minor-improvements-and-bug-fixes-2-3-0","dir":"Changelog","previous_headings":"","what":"Other minor improvements and bug fixes","title":"testthat 2.3.0","text":"compare.numeric() uses sophisticated default tolerance automatically skip tests rely numeric tolerance long doubles available (#940). JunitReporter now reports tests ISO 8601 UTC timezone uses maximum precision 3 decimal places (#923).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-221","dir":"Changelog","previous_headings":"","what":"testthat 2.2.1","title":"testthat 2.2.1","text":"CRAN release: 2019-07-25 Repair regression test_rd() add couple tests hopefully detect problem earlier future.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-220","dir":"Changelog","previous_headings":"","what":"testthat 2.2.0","title":"testthat 2.2.0","text":"CRAN release: 2019-07-22","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-features-2-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"testthat 2.2.0","text":"New verify_output() designed testing output aimed humans (commonly print methods error messages). regression test saves output way makes easy review. automatically skipped CRAN (#782, #834).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-2-2-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 2.2.0","text":".data.frame.testthat_results() now always returns data frame 13 columns (@jozefhajnala, #887). auto_test_package() now correctly handles helper files (tests/testthat/helper-*.R), automatically reloading code rerunning tests (@CorradoLanera, #376, #896). expect_match() now displays info even match length 0 (#867). expect_s3_class() gains new exact argument allows check exact class match, just inheritance (#885). fail() succeed() gain info argument, passed along expect(). test_examples() gets minor fixes: now returns results invisibly, doesn’t assume examples contain tests, documents shouldn’t using routinely (#841). test_file() calls Reporter$end_context() context started, fixing error TeamcityReporter (@atheriel, #883). skip() now reports reason skipping : Reason: {skip condition} (@patr1ckm, #868). skip_if() skip_if_not() now report Reason: {skip condition} TRUE Reason: {skip condition} TRUE respectively (@ patr1ckm, #868). skip_if_translated() now tests translation specific message. robust previous approach translation happens message--message, necessarily entire session (#879) (general, ’s impossible determine language R currently using). skip_on_covr() allows skip tests covr running. (@ianmcook, #895) expect_known_value() gains new serialisation version argument, defaulting 2. Prevents .rds files created hold reference objects making package appear require R >= 3.5 (#888 @jennybc).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-211","dir":"Changelog","previous_headings":"","what":"testthat 2.1.1","title":"testthat 2.1.1","text":"CRAN release: 2019-04-23 Fix test failures strict latin1 locale","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-210","dir":"Changelog","previous_headings":"","what":"testthat 2.1.0","title":"testthat 2.1.0","text":"CRAN release: 2019-04-22","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-expectations-2-1-0","dir":"Changelog","previous_headings":"","what":"New expectations","title":"testthat 2.1.0","text":"New expect_visible() expect_invisible() make easier check function call returns result visibly invisibly (#719). New expect_mapequal(x, y) checks x y names, value associated name (.e. compare values vector standardising order names) (#863). New expect_vector() wrapper around vctrs::vec_assert() making easy test vctrs definitions prototype size (#846). (Currently requires development version vctrs.)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"improvements-to-existing-expectations-2-1-0","dir":"Changelog","previous_headings":"","what":"Improvements to existing expectations","title":"testthat 2.1.0","text":"expectations give clearer error messages forget object expected arguments (#743). expect_equal() now correctly compares infinite values (#789). expect_equal_to_reference(), default value update now FALSE (@BrodieG, #683). expect_error() now returns error object documentated (#724). also now warns ’re using classed expectation ’re using class argument. good practice decouples error object (tends stable) rendering user (tends fragile) (#816). expect_identical() gains ... argument pass additional arguments identical() (#714). expect_lt(), expect_lte(), expect_gt() expect_gte() now handle Inf NA arguments appropriately (#732), longer require inputs numeric. expect_output() gains width argument, allowing control output width. inherit getOption(\"width\"), ensuring tests return results regardless environment (#805). expect_setequal() now works vector types (including lists), uses %%, rather sort(). also warns inputs named, suggests mental model expect_setequal() works wrong (#750). is_true() is_false() deprecated conflict functions tidyverse.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-2-1-0","dir":"Changelog","previous_headings":"","what":"Reporters","title":"testthat 2.1.0","text":"Reporter documentation considerably improved (#657). CheckReporter, used R CMD check, now includes count warnings. JUnitReporter longer replaces . class names (#753), creates output compatible Jenkins (#806, @comicfans). ListReporter now records number passed tests original results new columns (#675). ProgressReporter, default reporter, now: Automatically generates context file name. longer recommend use context() instead encourage delete , allowing context autogenerated file name. also eliminates error occurred tests can first context() (#700, #705). Gains update_interval parameter control often updates printed (default 0.1 s). prevents large printing overhead fast tests. (#701, @jimhester) Uses 3 character wide column display test successes, 999 successful tests can displayed without changing alignment (#712). reporter$end_reporter() now called testing completes successfully. ensures don’t get unnecessary output test fails partway (#727).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"skips-2-1-0","dir":"Changelog","previous_headings":"","what":"Skips","title":"testthat 2.1.0","text":"skip_if_offline() skips tests internet connection available (#685). skip_on_ci() skips tests continuous integration systems (@mbjoseph, #825) looking CI env var..","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-new-features-2-1-0","dir":"Changelog","previous_headings":"","what":"Other new features","title":"testthat 2.1.0","text":"New testthat_examples() testthat_example() make easy access new test files bundled package. used various examples make easier understand use package. New local_mock() allows mock function without add additional layer indentation with_mock() (#856).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-minor-improvements-and-bug-fixes-2-1-0","dir":"Changelog","previous_headings":"","what":"Other minor improvements and bug fixes","title":"testthat 2.1.0","text":"auto_test_package() works better recent devtools also watches src/ changes (#809). expect_s3_class() now works unquoting (@jalsalam, #771). expectation objects now contain failure message, even successful (#836) devtools::test() longer fails run multiple times within R session package containing Catch tests. (devtools #1832) New testing_package() retrieves name package currently tested (#699). run_testthat_tests C entrypoint registered robustly. skip() now always produces message length 1, expected elsewhere testthat (#791). Warnings passed even options(warn = 2) set (@yutannihilation, #721).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-201","dir":"Changelog","previous_headings":"","what":"testthat 2.0.1","title":"testthat 2.0.1","text":"CRAN release: 2018-10-13 Fix failing tests devtools 2.0.0","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-200","dir":"Changelog","previous_headings":"","what":"testthat 2.0.0","title":"testthat 2.0.0","text":"CRAN release: 2017-12-13","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"breaking-api-changes-2-0-0","dir":"Changelog","previous_headings":"","what":"Breaking API changes","title":"testthat 2.0.0","text":"“Can’t mock functions base packages”: can longer use with_mock() mock functions base packages, longer works R-devel due changes byte code compiler. recommend using mockery mockr instead. order arguments expect_equivalent() expect_error() changed slightly now pass ... another function. reveals number different errors, like: ‘’ must character vector ‘check.attributes’ must logical ‘tolerance’ numeric argument interpretable logical threw error unexpected class argument “quo” missing, default argument missing, default see one errors, check number, order, names arguments expectation. “Failure: (unknown)”. last release mistakenly failed test bare expectations wrapped inside test_that(). see “(unknown)” failure message, failing expectation previously weren’t seeing. well fixing failure, please also wrap inside test_that() informative name. “Error: argument already evaluated”: way expectations now need create labels changed, caused couple failures unusual usage combined Reduce, lapply(), Map(). Avoid functions favour loops. also recommend reading section quasiquotation support order create informative failure messages.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-and-improved-expectations-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"New and improved expectations","title":"testthat 2.0.0","text":"expect_condition() works like expect_error() captures condition, just error conditions (#621). expect_error() gains class argument allows make assertion class error object (#530). expect_reference() checks two names point object (#622). expect_setequal() compares two sets (stored vectors), ignoring duplicates differences order (#528).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-and-improved-skips-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"New and improved skips","title":"testthat 2.0.0","text":"skip_if() makes easy skip test condition true (#571). example, use skip_if(getRversion() <= 3.1) skip test older R versions. skip_if_translated() skips tests ’re running locale translations likely occur (#565). Use avoid spurious failures checking text error messages non-English locales. skip_if_not_installed() gains new minimum_version argument (#487, #499).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"known-good-values-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"Known good values","title":"testthat 2.0.0","text":"identified useful family expectations compares results expression known good value stored file. designed use conjunction git can see precisely changed, revert needed. expect_known_output() replaces expect_output_file(), soft-deprecated. now defaults update = TRUE warn, rather failing first run. gains print argument automatically print input (#627). also sets width option 80 ensure consistent output across environments (#514) expect_known_value() replaces expect_equal_to_reference(), soft-deprecated. gains update argument defaulting TRUE. changes behaviour previous version, soft-deprecated expect_equal_to_reference() gets update = FALSE. expect_known_failure() stored compares failure message expectation. ’s useful regression test developing informative failure messages expectations.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"quasiquotation-support-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"Quasiquotation support","title":"testthat 2.0.0","text":"expectations can now use unquoting (#626). makes much easier generate informative failure messages running tests loop. example take test: fails, ’ll see message Error: `f()` equal `* 10`. ’s hard diagnose don’t know iteration caused problem! unquote values using !!, get failure message `f(4L)` equal 40.. much easier diagnose! See ?quasi_label() details. (Note tidy evaluation per se, closely related. time can unquote quosures.)","code":"f <- function(i) if (i > 3) i * 9 else i * 10 for (i in 1:5) { expect_equal(f(i), i * 10) } for (i in 1:5) { expect_equal(f(!!i), !!(i * 10)) }"},{"path":[]},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"setup-and-teardown-2-0-0","dir":"Changelog","previous_headings":"New features","what":"Setup and teardown","title":"testthat 2.0.0","text":"New setup() teardown() functions allow run start end test file. useful want pair cleanup code code messes state (#536). Two new prefixes recognised test/ directory. Files starting setup run tests (unlike helpers run devtools::load_all()). Files starting teardown run tests completed (#589).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-new-features-2-0-0","dir":"Changelog","previous_headings":"New features","what":"Other new features","title":"testthat 2.0.0","text":"files now read written UTF-8 (#510, #605). is_testing() allows tell code run inside testing environment (#631). Rather taking run-time dependency testthat may want inline function package: ’s frequently useful combine interactive().","code":"is_testing <- function() { identical(Sys.getenv(\"TESTTHAT\"), \"true\") }"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-default-reporter-2-0-0","dir":"Changelog","previous_headings":"New features","what":"New default reporter","title":"testthat 2.0.0","text":"new default reporter, ReporterProgress, produces aesthetically pleasing output makes important information available upfront (#529). can return previous default setting options(testthat.default_reporter = \"summary\").","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-2-0-0","dir":"Changelog","previous_headings":"New features","what":"Reporters","title":"testthat 2.0.0","text":"Output colours tweaked consistent clang: warnings now magenta, skips blue. New default_reporter() check_reporter() returns default reporters interactive check environments (#504). New DebugReporter calls better version recover() case failures, errors, warnings (#360, #470). New JunitReporter generates reports JUnit compatible format. (#481, @lbartnik; #640, @nealrichardson; #575) New LocationReporter just prints location every expectation. useful locating segfaults C/C++ breakpoints (#551). SummaryReporter received number smaller tweaks Aborts testing soon limit given option testthat.summary.max_reports (default 10) reached (#520). New option testthat.summary.omit_dots = TRUE hides progress dots speeding tests small amount (#502). Bring back random praise encouragement accidentally dropped (#478). New option testthat.default_check_reporter, defaults \"check\". Continuous Integration system can set option evaluating package test sources order direct test result details known location. reporters now accept file argument initialization. provided, reporters write test results path. output destination can also controlled option testthat.output_file (#635, @nealrichardson).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"deprecated-functions-2-0-0","dir":"Changelog","previous_headings":"","what":"Deprecated functions","title":"testthat 2.0.0","text":"is_null() matches() deprecated conflict functions tidyverse (#523).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-2-0-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 2.0.0","text":"Updated Catch 1.9.6. testthat now understands makes use package routine registration mechanism required CRAN R >= 3.4.0. Better reporting deeply nested failures, limiting stack trace first last 10 entries (#474). Bare expectations notify reporter . achieved running tests inside test_code() default (#427, #498). behaviour can overridden setting wrap = FALSE test_dir() friends (#586). auto_test() auto_test_package() provide hash parameter enable switching faster, time-stamp-based modification detection (#598, @katrinleinweber). auto_test_package() works correctly windows (#465). capture_output_lines() now exported (#504). compare.character() works correctly vectors length > 5 (#513, @brodieG) compare.default() gains max_diffs argument defaults printing first 9 differences (#538). compare.numeric() respects check.attributes() expect_equivalent() correctly ignores attributes numeric vectors (#485). Output expectations (expect_output(), expect_message(), expect_warning(), expect_silent()) invisibly return first argument consistent expectations (#615). expect_length() works object length method, just vectors (#564, @nealrichardson) expect_match() now accepts explicit perl fixed arguments, adapts failure message value fixed. also affects expectations forward expect_match(), like expect_output(), expect_message(), expect_warning(), expect_error(). expect_match() escapes special regular expression characters printing (#522, @jimhester). expect_message(), expect_warning() expect_error() produce clearer failure messages. find_test_scripts() looks \\.[rR] extension (#492, @brodieG) test_dir(), test_package(), test_check() unset R_TESTS env var (#603) test_examples() now works installed packages well source packages (@jimhester, #532). test_dir(), test_package(), test_check() gain stop_on_failure stop_on_waring arguments control whether error signalled tests fail generate warnings (#609, #619). test_file() now triggers gc() tests run. helps ensure finalisers run earlier (#535). test_path() now generates correct path called within tools::testInstalledPackage() (#542). test_path() longer assumes path exists (#448). test_that() calls without expectations generate default skip() (#413). test_dir() gains load_helpers argument (#505). show_failures() simply prints failure occurs. makes easier show failures examples. with_mock() disallows mocking functions base packages, doesn’t work current development version R (#553).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-102","dir":"Changelog","previous_headings":"","what":"testthat 1.0.2","title":"testthat 1.0.2","text":"CRAN release: 2016-04-23 Ensure std::logic_error() constructed std::string() argument, avoid build errors Solaris.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-101","dir":"Changelog","previous_headings":"","what":"testthat 1.0.1","title":"testthat 1.0.1","text":"CRAN release: 2016-04-21 New expect_output_file() compare output function text file, optionally update (#443, @krlmlr). Properly scoped use + compilation C++ unit testing code using Catch gcc clang , Catch includes code strictly conform C++98 standard. (2) Fixed --bounds memory access routing Catch output Rprintf(). (2) Ensure unit tests run R-oldrel (remove use dir.exists()). Improved overriding calls exit() within Catch, ensure compatibility GCC 6.0. (@krlmlr) Hardened formatting difference messages, previously presence % characters affect output (#446, @krlmlr). Fixed errors expect_equal() comparing numeric vectors without attributes (#453, @krlmlr). auto_test() auto_test_package() show results current test run previously failed runs (#456, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-100","dir":"Changelog","previous_headings":"","what":"testthat 1.0.0","title":"testthat 1.0.0","text":"CRAN release: 2016-04-14","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"breaking-changes-1-0-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"testthat 1.0.0","text":"expectation() function now expects expectation type (one “success”, “failure”, “error”, “skip”, “warning”) first argument. ’re creating expectations, ’ll need use expect() instead (#437).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-expectations-1-0-0","dir":"Changelog","previous_headings":"","what":"New expectations","title":"testthat 1.0.0","text":"expectation system got thorough overhaul (#217). primarily makes easier add new expectations future, also included thorough review documentation, ensuring related expectations documented together, evocative names. One useful change expectations invisibly return input object. makes possible chain together expectations magrittr: (make style even easier, testthat now re-exports pipe, #412). exception rule expectations evaluate (.e. messages, warnings, errors, output etc), invisibly return NULL. functions now consistent: using NA cause failure errors/warnings/messages/output (.e. ’re missing), NULL fail aren’t errors/warnings/messages/output. previously didn’t work expect_output() (#323), error messages confusing expect_error(..., NA) (#342, @nealrichardson + @krlmlr, #317). Another change expect_output() now requires explicitly print output want test print method: expect_output(\"\", \"\") fail, expect_output(print(\"\"), \"\") succeed. six new expectations: expect_type() checks type object (#316), expect_s3_class() tests object S3 given class, expect_s4_class() tests object S4 given class (#373). recommend using specific expectations instead general expect_is(). expect_length() checks object expected length. expect_success() expect_failure() new expectations designed specifically testing expectations (#368). number older features deprecated: expect_more_than() expect_less_than() deprecated. Please use expect_gt() expect_lt() instead. takes_less_than() deprecated. () deprecated. Please use explicit individual forms expect_error(..., NA) , expect_warning(.., NA) .","code":"factor(\"a\") %>% expect_type(\"integer\") %>% expect_s3_class(\"factor\") %>% expect_length(1)"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"expectations-are-conditions-1-0-0","dir":"Changelog","previous_headings":"","what":"Expectations are conditions","title":"testthat 1.0.0","text":"Now expectations also conditions, R’s condition system used signal failures successes (#360, @krlmlr). known conditions (currently, “error”, “warning”, “message”, “failure”, “success”) converted expectations using new .expectation(). allows third-party test packages (assertthat, testit, ensurer, checkmate, assertive) seamlessly establish testthat compatibility issuing custom error conditions (e.g., structure(list(message = \"Error message\"), class = c(\"customError\", \"error\", \"condition\"))) implementing .expectation.customError(). assertthat package contains example.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-1-0-0","dir":"Changelog","previous_headings":"","what":"Reporters","title":"testthat 1.0.0","text":"reporters system class considerably refactored make existing reporters simpler make easier write new reporters. two main changes: Reporters classes now R6 classes instead Reference Classes. callbacks receive full context: add_results() passed context test well expectation. test_start() test_end() get context test. context_start() context_end() get context. Warnings now captured reported reporters. reporter output goes original standard output affected sink() expect_output() (#420, @krlmlr). default summary reporter lists warnings (#310), skipped tests (@krlmlr, #343). New option testthat.summary.max_reports limits number reports printed summary reporter. default 15 (@krlmlr, #354). MinimalReporter correct labels errors E failures F (#311). New FailReporter stop case failures errors tests (#308, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-1-0-0","dir":"Changelog","previous_headings":"","what":"Other","title":"testthat 1.0.0","text":"New functions capture_output(), capture_message(), capture_warnings() selectively capture function output. used expect_output(), expect_message() expect_warning() allow types output percolate (#410). try_again() allows retry code multiple times succeeds (#240). test_file(), test_check(), test_package() now attach testthat testing functions available. source_test_helpers() gets useful default path: testthat tests directory. defaults test_env() consistent source functions (#415). test_file() now loads helpers test directory running tests (#350). test_path() makes possible create paths files tests/testthat work interactively called tests (#345). Add skip_if_not() helper. Add skip_on_bioc() helper (@thomasp85). make_expectation() uses expect_equal(). setup_test_dir() removed. used previously, instead use source_test_helpers() find_test_scripts(). source_file() exports function testthat uses load files disk. test_that() returns logical indicates tests successful (#360, @krlmlr). find_reporter() (also high-level testing functions) support vector reporters. one reporter, MultiReporter created (#307, @krlmlr). with_reporter() used internally gains new argument start_end_reporter = TRUE (@krlmlr, 355). set_reporter() returns old reporter invisibly (#358, @krlmlr). Comparing integers non-numbers doesn’t raise errors anymore, falls back string comparison objects different lengths. Complex numbers compared using routine (#309, @krlmlr). compare.numeric() compare.character() received another overhaul. improve behaviour edge cases, provides strong foundation work. Added compare.POSIXt() better reporting datetime differences. expect_identical() is_identical_to() now use compare() detailed output differences (#319, @krlmlr). Added Catch v1.2.1 unit testing C++ code. See ?use_catch() details. (2)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-0110","dir":"Changelog","previous_headings":"","what":"testthat 0.11.0","title":"testthat 0.11.0","text":"CRAN release: 2015-10-14 Handle skipped tests TAP reporter (#262). New expect_silent() ensures code produces output, messages, warnings (#261). New expect_lt(), expect_lte(), expect_gt() expect_gte() comparison without equality (#305, @krlmlr). expect_output(), expect_message(), expect_warning(), expect_error() now accept NA second argument indicate output, messages, warnings, errors absent (#219). Praise gets diverse thanks praise package, ’ll now get random encouragement tests don’t pass. testthat longer muffles warning messages. don’t want see output, need explicitly quiet , use expectation captures (e.g. expect_warning()). (#254) Use tests inst/tests formally deprecated. Please move tests/testthat instead (#231). expect_match() now encodes match, well output, expectation message (#232). expect_is() gives better failure message testing multiple inheritance, e.g. expect_is(1:10, c(\"glm\", \"lm\")) (#293). Corrected argument order compare.numeric() (#294). comparison() constructure now checks arguments correct type length. bugs bug tests failed error like “values must length 1, FUN(X[[1]]) result length 2” (#279). Added skip_on_os(), skip tests specified operating systems (2). Skip test depends devtools installed (#247, @krlmlr) Added skip_on_appveyor() skip tests Appveyor (@lmullen). compare() shows detailed output differences character vectors different length (#274, @krlmlr). Detailed output expect_equal() doesn’t confuse expected actual values anymore (#274, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-0100","dir":"Changelog","previous_headings":"","what":"testthat 0.10.0","title":"testthat 0.10.0","text":"CRAN release: 2015-05-22 Failure locations now formatted R error locations. Add ‘invert’ argument find_tests_scripts(). allows one select tests match pattern. (#239, @jimhester). Deprecated library_if_available() removed. test (test_dir(), test_file(), test_package(), test_check()) functions now return testthat_results object contains results, can printed converted data frame. test_dir(), test_package(), test_check() added ... argument allows filtering test files using, e.g., Perl-style regular expressions,fixed character filtering. Arguments ... passed grepl() (@leeper). test_check() uses new reporter specifically designed R CMD check. displays summary end tests, designed <13 lines long test failures R CMD check display something useful. hopefully stop BDR calling testthat “test obfuscation suite” (#201). compare() now documented exported. Added numeric method long numeric vectors don’t match ’ll see examples problem (#177). line spacing compare.character() tweaked. skip_if_not_installed() skips tests package isn’t installed (#192). expect_that(, equals(b)) style testing soft-deprecated. keep working, ’s longer demonstrated , new expectations available expect_equal(, b) style. (#172) , testthat suppresses messages warnings tests (#189) New test_examples() lets run package examples tests. example counts one expectation succeeds code runs without errors (#204). New succeed() expectation always succeeds. skip_on_travis() allows skip tests run Travis CI. (Thanks @mllg) colourise() removed. (Colour still supported, via crayon package.) Mocks can now access values local call with_mock (#193, @krlmlr). equality expectations now documented together (#173); matching expectations also documented together.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-091","dir":"Changelog","previous_headings":"","what":"testthat 0.9.1","title":"testthat 0.9.1","text":"CRAN release: 2014-10-01 Bump R version dependency","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-09","dir":"Changelog","previous_headings":"","what":"testthat 0.9","title":"testthat 0.9","text":"CRAN release: 2014-09-22","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-features-0-9","dir":"Changelog","previous_headings":"","what":"New features","title":"testthat 0.9","text":"BDD: testhat now comes initial behaviour driven development (BDD) interface. language similar RSpec Ruby Mocha JavaScript. BDD tests read like sentences, make easier understand specification function. See ?describe() information examples. ’s now possible skip() test informative message - useful tests available certain conditions, CRAN, internet connection available (#141). skip_on_cran() allows skip tests run CRAN. take advantage code, ’ll need either use devtools, run Sys.setenv(NOT_CRAN = \"true\")) Simple mocking: with_mock() makes easy temporarily replace functions defined packages. useful testing code relies functions slow, unintended side effects access resources may available testing (#159, @krlmlr). new expectation, expect_equal_to_reference() added. tests equality reference value stored file (#148, @jonclayden).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-0-9","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 0.9","text":"auto_test_package() works , now uses devtools::load_all() higher fidelity loading (#138, #151). Bug compare.character() fixed, reported Georgi Boshnakov. colourise() now uses option testthat.use_colours (default: TRUE). FALSE, output colourised (#153, @mbojan). is_identical_to() calls .equal() generate informative error message two objects identical (#165). safe_digest() uses better strategy, returns NA directories (#138, #146). Random praise renabled default (!) (#164). Teamcity reporter now correctly escapes output messages (#150, @windelinckx). also uses nested suites include test names.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"deprecated-functions-0-9","dir":"Changelog","previous_headings":"","what":"Deprecated functions","title":"testthat 0.9","text":"library_if_available() deprecated.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-081","dir":"Changelog","previous_headings":"","what":"testthat 0.8.1","title":"testthat 0.8.1","text":"CRAN release: 2014-02-22 Better default environment test_check() test_package() allows S4 class creation tests compare.character() longer fails one value missing.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-08","dir":"Changelog","previous_headings":"","what":"testthat 0.8","title":"testthat 0.8","text":"CRAN release: 2014-02-20 testthat 0.8 comes new recommended structure storing tests. better meet CRAN recommended practices, testthat now recommend put tests tests/testthat, instead inst/tests (makes possible users choose whether install tests). new structure, ’ll need use test_check() instead test_packages() test file (usually tests/testthat.R) runs testthat unit tests. big improvement usability comes @kforner, contributed code allow default results (.e. produced SummaryReporter) include source references can see exactly failures occurred.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-reporters-0-8","dir":"Changelog","previous_headings":"","what":"New reporters","title":"testthat 0.8","text":"MultiReporter, combines several reporters one. (Thanks @kforner) ListReporter, captures test results file, context, test elapsed time. test_dir, test_file, test_package test_check now use ListReporter invisibly return summary tests data frame. (Thanks @kforner) TeamCityReporter produce output compatible TeamCity continuous integration environment. (Thanks @windelinckx) SilentReporter testthat can test calls test_that. (Thanks @craigcitro, #83)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-expectations-0-8","dir":"Changelog","previous_headings":"","what":"New expectations","title":"testthat 0.8","text":"expect_null() is_null check object NULL (#78) expect_named() has_names() check names vector (#79) expect_more_than(), is_more_than(), expect_less_than(), is_less_than() check values threshold. (#77, thanks @jknowles)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-0-8","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 0.8","text":"expect_that() (thus expect_* functions) now invisibly return expectation result, stops info label arguments length > 1 (thanks @kforner) fixed two bugs source_dir(): look source scripts right place, use chdir argument. using expect_equal() compare strings, default output failure provides lot information, hopefully help make finding string mismatches easier. SummaryReporter max_reports option limit number detailed failure reports show. (Thanks @crowding) Tracebacks now also contain information functions came (information available). matches expect_match now pass additional arguments grepl can use fixed = TRUE, perl = TRUE ignore.case = TRUE control details match. expect_match now correctly fails match NULL. (#100) expect_output, expect_message, expect_warning expect_error also pass … grepl, can use fixed = TRUE, perl = TRUE ignore.case = TRUE Removed stringr evaluate dependencies. () function makes possible negate tests. example, expect_that(f(), (throws_error())) asserts f() throw error. Make dir_state less race-y. (Thanks @craigcitro, #80) auto_test now pays attention ‘reporter’ argument (Thanks @crowding, #81) get_reporter(), set_reporter() with_reporter() now exported (#102)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-071","dir":"Changelog","previous_headings":"","what":"testthat 0.7.1","title":"testthat 0.7.1","text":"CRAN release: 2013-03-27 Ignore attributes is_true is_false (#49) make_expectation works types input (#52) Now works better evaluate 0.4.3. new fail() function always forces failure test. Suggested Richie Cotton (#47) Added TapReporter produce output compatible “test anything protocol”. Contributed Dan Keshet. Fixed auto_test identify wrong files changed. (Thanks Peter Meilstrup)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-07","dir":"Changelog","previous_headings":"","what":"testthat 0.7","title":"testthat 0.7","text":"CRAN release: 2012-06-27 SummaryReporter: still return informative messages even tests defined (just bare expectations). (Fixes #31) Improvements reference classes (Thanks John Chambers) Bug fixes nothing generated gives_warning / shows_message. (Thanks Bernd Bischl) New make_expectation function programmatically generate equality expectation. (Fixes #24) SummaryReporter: don’t get praise tests. Depend methods rather requiring testthat works run Rscript auto_test now normalises paths enable better identification file changes, fixes bug instantiating new reporter object.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-06","dir":"Changelog","previous_headings":"","what":"testthat 0.6","title":"testthat 0.6","text":"CRAN release: 2011-12-30 mutatr classes replaced ReferenceClasses. Better documentation short-hand expectations. test_dir test_package gain new filter argument allows restrict tests run.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-05","dir":"Changelog","previous_headings":"","what":"testthat 0.5","title":"testthat 0.5","text":"CRAN release: 2011-06-01 bare expectations now correctly throw errors ","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-04","dir":"Changelog","previous_headings":"","what":"testthat 0.4","title":"testthat 0.4","text":"CRAN release: 2011-03-20 autotest correctly loads code executes tests environment contexts never closed opened, always closed end file fixed small bug test_dir test given environment expect_* short cut functions gain label argument, thanks Steve Lianoglou","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-03","dir":"Changelog","previous_headings":"","what":"testthat 0.3","title":"testthat 0.3","text":"CRAN release: 2010-08-31 expectations now shortcut form, instead expect_that(, is_identical_to(b)) can expect_identical(, b) new shows_message gives_warning expectations test warnings messages expect_that, equals, is_identical_to is_equivalent now additional label argument allows control appearance text used expected object (expect_that) actual object (functions) failure messages. useful loops run tests otherwise variable names identical, ’s difficult tell iteration caused failure. executing bare tests gives nicer output expectations now give information failure make easier track problem. test_file test_dir now run code separate environment avoid pollution global environment. also temporary change working directory tests can use relative paths. test_package makes easier run tests installed package. Code run manner access non-exported functions objects. errors failures occur, test_package throw error, making suitable use R CMD check.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-02","dir":"Changelog","previous_headings":"","what":"testthat 0.2","title":"testthat 0.2","text":"CRAN release: 2010-07-25 colourise also works screen terminal equals expectation provides information failure expect_that extra info argument allow pass extra information ’d like included message - helpful ’re using loop run tests is_equivalent_to: new expectation tests equality ignoring attributes library_if_available now works! (thanks report fix Felix Andrews) specify larger width join pieces back together whenever deparse used (thanks report fix Felix Andrews) test_dir now looks files starting test (test- )","code":""}] +[{"path":[]},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://testthat.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://testthat.r-lib.org/dev/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 testthat authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"expectation-basics","dir":"Articles","previous_headings":"","what":"Expectation basics","title":"Custom expectations","text":"three main parts writing expectation, illustrated expect_length():","code":"expect_length <- function(object, n) { # 1. Capture object and label act <- quasi_label(rlang::enquo(object), arg = \"object\") # 2. Call expect() act$n <- length(act$val) expect( act$n == n, sprintf(\"%s has length %i, not length %i.\", act$lab, act$n, n) ) # 3. Invisibly return the value invisible(act$val) }"},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"quasi-labelling","dir":"Articles","previous_headings":"Expectation basics","what":"Quasi-labelling","title":"Custom expectations","text":"first step expectation capture actual object, generate label use failure occur. testthat expectations support quasiquotation can unquote variables. makes easier generate good labels expectation called function within loop. convention, first argument every expect_ function called object, capture ’s value (val) label (lab) act <- quasi_label(enquo(object)), act short actual.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"verify-the-expectation","dir":"Articles","previous_headings":"Expectation basics","what":"Verify the expectation","title":"Custom expectations","text":"Next, verify expectation. often involves little computation (just figuring length), typically store results back act object. Next call expect(). two arguments: ok: expectation successful? usually easy write failure_message: informative error message reported user can diagnose problem. often hard write! historical reasons, built-expectations generate sprintf(), today ’d recommend using glue package","code":""},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"invisibly-return-the-input","dir":"Articles","previous_headings":"Expectation basics","what":"Invisibly return the input","title":"Custom expectations","text":"Expectation functions called primarily side-effects (triggering failure), invisibly return input, act$val. allows expectations chained:","code":"mtcars %>% expect_type(\"list\") %>% expect_s3_class(\"data.frame\") %>% expect_length(11)"},{"path":"https://testthat.r-lib.org/dev/articles/custom-expectation.html","id":"succeed-and-fail","dir":"Articles","previous_headings":"","what":"succeed() and fail()","title":"Custom expectations","text":"expectations complex logic governing success failure occurs, can use succeed() fail(). simple wrappers around expect() allow write code looks like :","code":"expect_length <- function(object, n) { act <- quasi_label(rlang::enquo(object), arg = \"object\") act$n <- length(act$val) if (act$n == n) { succeed() return(invisible(act$val)) } message <- sprintf(\"%s has length %i, not length %i.\", act$lab, act$n, n) fail(message) }"},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"setup","dir":"Articles","previous_headings":"","what":"Setup","title":"Running tests in parallel","text":"enable parallel testing, must first using 3rd edition1. add following line DESCRIPTION: default, testthat use getOption(\"Ncpus\", 2) cores. increase value development machine recommend setting TESTTHAT_CPUS .Renviron. easiest way call usethis::edit_r_environ() add something like following: Tests run alphabetical order default, can often improve performance starting slowest tests first. Specify tests supplying comma separated list glob patterns2 Config/testthat/start-first field DESCRIPTION, e.g.:","code":"Config/testthat/parallel: true TESTTHAT_CPUS=4 Config/testthat/start-first: watcher, parallel*"},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"basic-operation","dir":"Articles","previous_headings":"","what":"Basic operation","title":"Running tests in parallel","text":"worker begins loading testthat package tested. runs setup files (existing setup files ’ll need make sure work executed parallel). testthat runs test files parallel. worker pool initialized, testthat starts sending test files workers, default alphabetical order: soon subprocess finished, receives another file, files done. means state persisted across test files: options reset, loaded packages unloaded, global environment cleared, etc. responsible making sure file leaves world finds .","code":""},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"common-problems","dir":"Articles","previous_headings":"","what":"Common problems","title":"Running tests in parallel","text":"tests fail stochastically (.e. sometimes work sometimes fail) may accidentally introduced dependency test files. sort dependency hard track due random nature, ’ll need check tests make sure ’re accidentally changing global state. set_state_inspector() make easier. use packaged scope test fixtures, ’ll need review make sure work parallel. example, previously creating temporary database test directory, ’d need instead create session temporary directory process gets independent version.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"performance","dir":"Articles","previous_headings":"","what":"Performance","title":"Running tests in parallel","text":"overhead associated running tests parallel: Startup cost linear number subprocesses, need create loop. 50ms laptop. subprocess needs load testthat tested package, happens parallel, much . Clean time linear number subprocesses, 80ms per subprocess laptop. seems sending message (.e. passing failing expectation) 2ms currently. total cost includes sending message, receiving , replying non-parallel reporter. overhead generally means many test files take short amount time, ’re unlikely see huge benefit using parallel tests. example, testthat takes 10s run tests serial, 8s run tests parallel.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"default-reporters","dir":"Articles","previous_headings":"Reporters","what":"Default reporters","title":"Running tests in parallel","text":"See default_reporter() testthat selects default reporter devtools::test() testthat::test_local(). short, testthat selects ProgressReporter non-parallel ParallelProgressReporter parallel tests default. (testthat test functions, like test_check(), test_file() , etc. select different reporters default.)","code":""},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"parallel-support","dir":"Articles","previous_headings":"Reporters","what":"Parallel support","title":"Running tests in parallel","text":"reporters support parallel tests. reporter passed devtools::test(), testthat::test_dir(), etc. directly, support parallel tests, testthat runs test files sequentially. Currently following reporters don’t support parallel tests: DebugReporter, currently possible debug subprocesses. JunitReporter, reporter records timing information test block, currently available reporters support multiple active test files. (See “Writing parallel reporters” .) LocationReporter testthat currently include location information successful tests running parallel, minimize messaging processes. StopReporter, reporter testthat uses interactive expect_that() calls. built-reporters support parallel tests, subtle differences: Reporters stop certain number failures can stop end test file. Reporters report information file , unless support parallel updates. E.g. ProgressReporter update display test file complete. standard output standard error, .e. print(), cat(), message(), etc. output test files lost currently. want use cat() message() print-debugging test cases, best temporarily run tests sequentially, changing Config entry DESCRIPTION selecting non-parallel reporter, e.g. CheckReporter:","code":"devtools::test(filter = \"badtest\", reporter = \"check\")"},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"writing-parallel-reporters","dir":"Articles","previous_headings":"Reporters","what":"Writing parallel reporters","title":"Running tests in parallel","text":"support parallel tests, reporter must able function test files run subprocess. example DebugReporter support parallel tests, requires direct interaction frames subprocess. running parallel, testthat provide location information (source references) test successes. support parallel tests, reporter must set self$capabilities$parallel_support TRUE initialize() method: running parallel, testthat runs reporter main process, relays information reporter test code transparently. (Currently reporter even know tests running parallel.) reporter support parallel updates (see ), testthat internally caches calls reporter methods subprocesses, test file complete. reporters prepared running multiple test files concurrently. test file complete, testthat calls reporter’s $start_file() method, relays $start_test() , $end_test(), $add_result(), etc. calls order came subprocess, calls $end_file() .","code":"... initialize = function(...) { super$initialize(...) self$capabilities$parallel_support <- TRUE ... } ..."},{"path":"https://testthat.r-lib.org/dev/articles/parallel.html","id":"parallel-updates","dir":"Articles","previous_headings":"Reporters","what":"Parallel updates","title":"Running tests in parallel","text":"ParallelProgressReporter supports parallel updates. means message subprocess comes , reporter updated immediately. work, reporter must able handle multiple test files concurrently. reporter declares parallel update support setting self$capabilities$parallel_updates TRUE: reporters, testthat cache messages subprocesses. Instead, message comes : calls $start_file() method, letting reporter know file following calls apply . means reporter can receive multiple $start_file() calls file. relays message subprocess, calling appropriate $start_test() , $add_result(), etc. method. testthat also calls new $update() method reporter regularly, even receive messages subprocess. (Currently aims every 100ms, guarantees.) $update() method may implement spinner let user know tests running.","code":"... initialize = function(...) { super$initialize(...) self$capabilities$parallel_support <- TRUE self$capabilities$parallel_updates <- TRUE ... } ..."},{"path":"https://testthat.r-lib.org/dev/articles/skipping.html","id":"basics","dir":"Articles","previous_headings":"","what":"Basics","title":"Skipping tests","text":"testthat comes variety helpers common situations: skip_on_cran() skips tests CRAN. useful slow tests tests occasionally fail reasons outside control. skip_on_os() allows skip tests specific operating system. Generally, strive avoid much possible (code works platforms), sometimes ’s just possible. skip_on_ci() skips tests continuous integration platforms (e.g. GitHub Actions, Travis, Appveyor). can also easily implement using either skip_if() skip_if_not(), take expression yield single TRUE FALSE. reporters show tests skipped. testthat 3.0.0, ProgressReporter (used interactively) CheckReporter (used inside R CMD check) also display summary skips across tests. looks something like : keep eye developing interactively make sure ’re accidentally skipping wrong things.","code":"── Skipped tests ─────────────────────────────────────────────────────── ● No token (3) ● On CRAN (1)"},{"path":"https://testthat.r-lib.org/dev/articles/skipping.html","id":"helpers","dir":"Articles","previous_headings":"","what":"Helpers","title":"Skipping tests","text":"find using skip_if()/skip_if_not() expression across multiple tests, ’s good idea create helper function. function start skip_ live test/helper-{something}.R file:","code":"skip_if_dangerous <- function() { if (!identical(Sys.getenv(\"DANGER\"), \"\")) { skip(\"Not run in dangerous environments.\") } else { invisible() } }"},{"path":"https://testthat.r-lib.org/dev/articles/skipping.html","id":"embedding-skip-in-package-functions","dir":"Articles","previous_headings":"","what":"Embedding skip() in package functions","title":"Skipping tests","text":"Another useful technique can sometimes useful build skip() directly package function. example take look pkgdown:::convert_markdown_to_html(), absolutely, positively work Pandoc tool unavailable: Pandoc available convert_markdown_to_html() executes, throws error unless appears part test run, case test skipped. alternative implementing custom skipper, e.g. skip_if_no_pandoc(), inserting many pkgdown’s tests. don’t want pkgdown runtime dependency testthat, pkgdown includes copy testthat::is_testing(): might look like code appears still runtime dependency testthat, call testthat::skip(). testthat::skip() executed test run, implies testthat installed. mixed feelings approach. one hand, feels elegant concise, absolutely guarantees ’ll never miss needed skip one tests. hand, mixes code tests unusual way, ’re focused tests, ’s easy miss fact package function contains skip().","code":"convert_markdown_to_html <- function(in_path, out_path, ...) { if (rmarkdown::pandoc_available(\"2.0\")) { from <- \"markdown+gfm_auto_identifiers-citations+emoji+autolink_bare_uris\" } else if (rmarkdown::pandoc_available(\"1.12.3\")) { from <- \"markdown_github-hard_line_breaks+tex_math_dollars+tex_math_single_backslash+header_attributes\" } else { if (is_testing()) { testthat::skip(\"Pandoc not available\") } else { abort(\"Pandoc not available\") } } ... } is_testing <- function() { identical(Sys.getenv(\"TESTTHAT\"), \"true\") }"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"basic-workflow","dir":"Articles","previous_headings":"","what":"Basic workflow","title":"Snapshot tests","text":"’ll illustrate basic workflow simple function generates HTML heading. can optionally include id attribute, allows construct link directly heading. Testing simple function relatively painful. write test carefully escape newlines quotes. re-read test future, escaping makes hard tell exactly ’s supposed return. great place use snapshot testing. make two changes code: use expect_snapshot() instead expect_equal() wrap call cat() (avoid [1] output, like first interactive example). yields following test: run test first time, automatically generates reference output, prints , can visually confirm ’s correct. output automatically saved _snaps/{name}.md. name snapshot matches test file name — e.g. test test-pizza.R snapshot saved test/testthat/_snaps/pizza.md. file name suggests, markdown file, ’ll explain shortly. run test , ’ll succeed: change underlying code, say tweak indenting, test fail: deliberate change, can follow advice message update snapshots file running snapshot_accept(\"pizza\"); otherwise can fix bug tests pass . (can also accept snapshot files snapshot_accept()).","code":"bullets <- function(text, id = NULL) { paste0( \"\\n\", paste0(\"
                        • \", text, \"<\/li>\\n\", collapse = \"\"), \"<\/ul>\\n\" ) } cat(bullets(\"a\", id = \"x\")) #>
                            #>
                          • a<\/li> #> <\/ul> test_that(\"bullets\", { expect_equal(bullets(\"a\"), \"
                              \\n
                            • a<\/li>\\n<\/ul>\\n\") expect_equal(bullets(\"a\", id = \"x\"), \"
                                \\n
                              • a<\/li>\\n<\/ul>\\n\") }) #> Test passed test_that(\"bullets\", { expect_snapshot(cat(bullets(\"a\"))) expect_snapshot(cat(bullets(\"a\", \"b\"))) }) #> -- Warning: bullets ------------------------------------------------------------ #> Adding new snapshot: #> Code #> cat(bullets(\"a\")) #> Output #>
                                  #>
                                • a<\/li> #> <\/ul> #> #> -- Warning: bullets ------------------------------------------------------------ #> Adding new snapshot: #> Code #> cat(bullets(\"a\", \"b\")) #> Output #>
                                    #>
                                  • a<\/li> #> <\/ul> test_that(\"bullets\", { expect_snapshot(cat(bullets(\"a\"))) expect_snapshot(cat(bullets(\"a\", \"b\"))) }) #> Test passed bullets <- function(text, id = NULL) { paste0( \"\\n\", paste0(\"
                                  • \", text, \"<\/li>\\n\", collapse = \"\"), \"<\/ul>\\n\" ) } test_that(\"bullets\", { expect_snapshot(cat(bullets(\"a\"))) expect_snapshot(cat(bullets(\"a\", \"b\"))) }) #> -- Failure: bullets ------------------------------------------------------------ #> Snapshot of code has changed: #> old | new #> [2] cat(bullets(\"a\")) | cat(bullets(\"a\")) [2] #> [3] Output | Output [3] #> [4]
                                      |
                                        [4] #> [5]
                                      • a<\/li> -
                                      • a<\/li> [5] #> [6] <\/ul> | <\/ul> [6] #> #> * Run `testthat::snapshot_accept('snapshotting.Rmd')` to accept the change. #> * Run `testthat::snapshot_review('snapshotting.Rmd')` to interactively review the change. #> #> -- Failure: bullets ------------------------------------------------------------ #> Snapshot of code has changed: #> old | new #> [2] cat(bullets(\"a\", \"b\")) | cat(bullets(\"a\", \"b\")) [2] #> [3] Output | Output [3] #> [4]
                                          |
                                            [4] #> [5]
                                          • a<\/li> -
                                          • a<\/li> [5] #> [6] <\/ul> | <\/ul> [6] #> #> * Run `testthat::snapshot_accept('snapshotting.Rmd')` to accept the change. #> * Run `testthat::snapshot_review('snapshotting.Rmd')` to interactively review the change. #> Error: #> ! Test failed"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"snapshot-format","dir":"Articles","previous_headings":"Basic workflow","what":"Snapshot format","title":"Snapshot tests","text":"Snapshots recorded using subset markdown. might wonder use markdown? ’s important snapshots readable humans, humans look code reviews. Reviewers often don’t run code still want understand changes. ’s snapshot file generated test : test starts # {test name}, level 1 heading. Within test, snapshot expectation indented four spaces, .e. code, separated ---, horizontal rule.","code":"# bullets
                                            • a<\/li> <\/ul> ---
                                              • a<\/li> <\/ul>"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"interactive-usage","dir":"Articles","previous_headings":"Basic workflow","what":"Interactive usage","title":"Snapshot tests","text":"snapshot output uses name current test file current test, snapshot expectations don’t really work run interactively console. Since can’t automatically find reference output, instead just print current value manual inspection.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"other-types-of-output","dir":"Articles","previous_headings":"","what":"Other types of output","title":"Snapshot tests","text":"far ’ve focussed snapshot tests output printed console. expect_snapshot() also captures messages, errors, warnings1. following function generates output, message, warning: expect_snapshot() captures : Capturing errors slightly difficult expect_snapshot() fail ’s error: safety valve ensures don’t accidentally write broken code. deliberately snapshot error, ’ll specifically request error = TRUE: code gets longer, like put error = TRUE front ’s little obvious:","code":"f <- function() { print(\"Hello\") message(\"Hi!\") warning(\"How are you?\") } test_that(\"f() makes lots of noise\", { expect_snapshot(f()) }) #> -- Warning: f() makes lots of noise -------------------------------------------- #> Adding new snapshot: #> Code #> f() #> Output #> [1] \"Hello\" #> Message #> Hi! #> Condition #> Warning in `f()`: #> How are you? test_that(\"you can't add a number and a letter\", { expect_snapshot(1 + \"a\") }) #> -- Error: you can't add a number and a letter ---------------------------------- #> `1 + \"a\"` threw an unexpected error. #> Message: non-numeric argument to binary operator #> Class: simpleError/error/condition #> Error: #> ! Test failed test_that(\"you can't add a number and a letter\", { expect_snapshot(1 + \"a\", error = TRUE) }) #> -- Warning: you can't add a number and a letter -------------------------------- #> Adding new snapshot: #> Code #> 1 + \"a\" #> Condition #> Error in `1 + \"a\"`: #> ! non-numeric argument to binary operator test_that(\"you can't add weird things\", { expect_snapshot(error = TRUE, { 1 + \"a\" mtcars + iris mean + sum }) }) #> -- Warning: you can't add weird things ----------------------------------------- #> Adding new snapshot: #> Code #> 1 + \"a\" #> Condition #> Error in `1 + \"a\"`: #> ! non-numeric argument to binary operator #> Code #> mtcars + iris #> Condition #> Error in `Ops.data.frame()`: #> ! '+' only defined for equally-sized data frames #> Code #> mean + sum #> Condition #> Error in `mean + sum`: #> ! non-numeric argument to binary operator"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"snapshotting-values","dir":"Articles","previous_headings":"","what":"Snapshotting values","title":"Snapshot tests","text":"expect_snapshot() used snapshot function records everything: code run, printed output, messages, warnings, errors. care return value rather side-effects, may might use expect_snapshot_value() instead. offers number serialisation approaches provide tradeoff accuracy human readability.","code":"test_that(\"can snapshot a simple list\", { x <- list(a = list(1, 5, 10), b = list(\"elephant\", \"banana\")) expect_snapshot_value(x) }) #> -- Warning: can snapshot a simple list ----------------------------------------- #> Adding new snapshot: #> { #> \"a\": [ #> 1, #> 5, #> 10 #> ], #> \"b\": [ #> \"elephant\", #> \"banana\" #> ] #> }"},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"whole-file-snapshotting","dir":"Articles","previous_headings":"","what":"Whole file snapshotting","title":"Snapshot tests","text":"expect_snapshot(), expect_snapshot_output(), expect_snapshot_error(), expect_snapshot_value() use one snapshot file per test file. doesn’t work file types — example, happens want snapshot image? expect_snapshot_file() provides alternative workflow generates one snapshot per expectation, rather one file per test. Assuming ’re test-burger.R snapshot created expect_snapshot_file(code_that_returns_path_to_file(), \"toppings.png\") saved tests/testthat/_snaps/burger/toppings.png. future change code creates different file saved tests/testthat/_snaps/burger/toppings.new.png. Unlike expect_snapshot() friends, expect_snapshot_file() can’t provide automatic diff test fails. Instead ’ll need call snapshot_review(). launches Shiny app allows visually review change approve ’s deliberate: display varies based file type (currently text files, common image files, csv files supported). Sometimes failure occurs non-interactive environment can’t run snapshot_review(), e.g. R CMD check. case, easiest fix retrieve .new file, copy appropriate directory, run snapshot_review() locally. code run CI platform, ’ll need start downloading run “artifact”, contains check folder. cases, don’t expect use expect_snapshot_file() directly. Instead, ’ll use via wrapper best gracefully skip tests differences platform package versions make unlikely generate perfectly reproducible output.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/snapshotting.html","id":"previous-work","dir":"Articles","previous_headings":"","what":"Previous work","title":"Snapshot tests","text":"first time testthat attempted provide snapshot testing (although ’s first time knew languages called ). section describes previous attempts believe new approach better. verify_output() three main drawbacks: supply path output saved. seems like small issue, thinking good name, managing difference interactive test-time paths introduces surprising amount friction. always overwrites previous result; automatically assuming changes correct. means use git ’s easy accidentally accept unwanted changes. ’s relatively coarse grained, means tests use tend keep growing growing. expect_known_output() finer grained version verify_output() captures output single function. requirement produce path individual expectation makes even painful use. expect_known_value() expect_known_hash() disadvantages expect_known_output(), also produce binary output meaning can’t easily review test differences pull requests.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"test-files","dir":"Articles","previous_headings":"","what":"Test files","title":"Special files","text":"bread butter testthat. Test files live tests/testthat/, start either test- test_, end .r .R. recommend organising test files ’s one--one correspondence files R/ files tests/testthat/ (e.g.) R/myfile.R matching tests/testthat/test-myfile.R. correspondence maintained functions like usethis::use_r() usethis::use_test() taken advantage functions like devtools::test_active_file() devtools::test_coverage_active_file(). Test files executed alphabetical order, strive avoid dependencies test files. principle, able run test files order even time.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"helper-files","dir":"Articles","previous_headings":"","what":"Helper files","title":"Special files","text":"Helper files live tests/testtthat/, start helper, end .r .R. sourced devtools::load_all() (’re available interactively developing packages) test_check() friends (’re available matter tests executed). Helper files useful place functions ’ve extracted repeated code tests, whether test fixtures (vignette(\"test-fixtures\")), custom expectations (vignette(\"custom-expectations\")), skip helpers (vignette(\"skipping\")).","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"setup-files","dir":"Articles","previous_headings":"","what":"Setup files","title":"Special files","text":"Setup files live tests/testthat/, start setup, end .r .R. Typically one setup file , convention, tests/testthat/setup.R. Setup files sourced test_check() friends (’re available matter tests executed), sourced devtools::load_all(). Setup files good place put truly global test setup impractical build every single test might tailored test execution non-interactive remote environments. Examples: Turning behaviour aimed interactive user, messaging writing clipboard. Setting cache folder. setup reversed test execution (.e. needs torn ), recommend maintaining teardown code alongside setup code, setup.R, makes easier ensure stay sync. artificial environment teardown_env() exists magical handle use withr::defer() withr::local_*(). legacy approach (still works, longer recommended) put teardown code tests/testthat/teardown.R. ’s setup.R example reprex package, turn clipboard HTML preview functionality testing: Since just modifying options , can even concise use pre-built function withr::local_options() pass teardown_env() .local_envir:","code":"op <- options(reprex.clipboard = FALSE, reprex.html_preview = FALSE) withr::defer(options(op), teardown_env()) withr::local_options( list(reprex.clipboard = FALSE, reprex.html_preview = FALSE), .local_envir = teardown_env() )"},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"teardown-files","dir":"Articles","previous_headings":"Setup files","what":"Teardown files","title":"Special files","text":"Teardown files live tests/testhat/, start teardown end .r .R. executed tests run, longer recommend using ’s easier check clean every mess make interleave setup tear code described .","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"snapshot-files","dir":"Articles","previous_headings":"","what":"Snapshot files","title":"Special files","text":"Snapshot files live tests/testthat/_snaps/. Snapshot file named automatically based name test file tests/testthat/test-one.R generated tests/testthat/_snaps/one.md. Learn snapshot tests vignette(\"snapshotting\").","code":""},{"path":"https://testthat.r-lib.org/dev/articles/special-files.html","id":"other-files-and-folders","dir":"Articles","previous_headings":"","what":"Other files and folders","title":"Special files","text":"files folders tests/testthat/ ignored testthat, making good place store persistent test data. Since precise location test/testthat/ directory varies slightly depending ’re running test, recommend creating paths files directories using test_path().","code":""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"test-hygiene","dir":"Articles","previous_headings":"","what":"Test hygiene","title":"Test fixtures","text":"Take nothing memories, leave nothing footprints. ― Chief Si’ahl Ideally, test leave world exactly found . often need make changes order exercise every part code: Create file directory Create resource external system Set R option Set environment variable Change working directory Change aspect tested package’s state can clean changes get back clean slate? Scrupulous attention cleanup just courtesy fastidious. also self-serving. state world test starting state test + 1. Tests change state willy-nilly eventually end interfering ways can difficult debug. tests written implicit assumption starting state, usually whatever tabula rasa means target domain package. accumulate enough sloppy tests, eventually find asking programming equivalent questions like “forgot turn oven?” “didn’t clean dog?”. ’s also important setup cleanup easy use working interactively. test fails, want able quickly recreate exact environment test run can interactively experiment figure went wrong. article introduces powerful technique allows solve problems: test fixtures. ’ll begin introduction tools make fixtures possible, talk exactly test fixture , show examples. Much vignette derived https://www.tidyverse.org/blog/2020/04/self-cleaning-test-fixtures/; first encounter .exit() withr::defer(), ’d recommend starting blog gives gentler introduction. vignette moves little faster since ’s designed reference doc.","code":"library(testthat)"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"foundations","dir":"Articles","previous_headings":"","what":"Foundations","title":"Test fixtures","text":"can talk test fixtures, need lay foundations help understand work. ’ll motivate discussion sloppy() function prints number specific number significant digits adjusting R option: Notice pi prints differently call sloppy(). Calling sloppy() side effect: changes digits option globally, just within scope operations. want avoid1.","code":"sloppy <- function(x, sig_digits) { options(digits = sig_digits) print(x) } pi #> [1] 3.141593 sloppy(pi, 2) #> [1] 3.1 pi #> [1] 3.1"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"on-exit","dir":"Articles","previous_headings":"Foundations","what":"on.exit()","title":"Test fixtures","text":"first function need know base R’s .exit(). .exit() calls code supplied first argument current function exits, regardless whether returns value errors. can use .exit() clean ensuring every mess-making function call paired .exit() call cleans . can use idea turn sloppy() neat(): make use useful pattern options() implements: call options(digits = sig_digits) sets digits option (invisibly) returns previous value digits. can use value restore previous options. .exit() also works tests: three main drawbacks .exit(): always call add = TRUE = FALSE. ensure call added list deferred tasks (instead replaces) added front stack (back, cleanup occurs reverse order setup). arguments matter ’re using multiple .exit() calls, ’s good habit always use avoid potential problems road. doesn’t work outside function test. run following code global environment, won’t get error, cleanup code never run: annoying running tests interactively. can’t program ; .exit() always works inside current function can’t wrap repeated .exit() code helper function. resolve drawbacks, use withr::defer().","code":"neat <- function(x, sig_digits) { op <- options(digits = sig_digits) on.exit(options(op), add = TRUE, after = FALSE) print(x) } pi #> [1] 3.141593 neat(pi, 2) #> [1] 3.1 pi #> [1] 3.141593 test_that(\"can print one digit of pi\", { op <- options(digits = 1) on.exit(options(op), add = TRUE, after = FALSE) expect_output(print(pi), \"3\") }) #> Test passed pi #> [1] 3.141593 op <- options(digits = 1) on.exit(options(op), add = TRUE, after = FALSE)"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"withrdefer","dir":"Articles","previous_headings":"Foundations","what":"withr::defer()","title":"Test fixtures","text":"withr::defer() resolves main drawbacks .exit(). First, behaviour want default; extra arguments needed: Second, works called global environment. Since global environment isn’t perishable, like test environment , call deferred_run() explicitly execute deferred events. can also clear , without running, deferred_clear(). Finally, withr::defer() lets pick function bind clean behaviour . makes possible create helper functions.","code":"neat <- function(x, sig_digits) { op <- options(digits = sig_digits) withr::defer(options(op)) print(x) } withr::defer(print(\"hi\")) #> Setting deferred event(s) on global environment. #> * Execute (and clear) with `deferred_run()`. #> * Clear (without executing) with `deferred_clear()`. withr::deferred_run() #> [1] \"hi\""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"local-helpers","dir":"Articles","previous_headings":"Foundations","what":"“Local” helpers","title":"Test fixtures","text":"Imagine many functions want temporarily set digits option. Wouldn’t nice write helper function automate? Unfortunately can’t write helper .exit(): code doesn’t work cleanup happens soon, local_digits() exits, neat() finishes. Fortunately, withr::defer() allows us solve problem providing envir argument allows control cleanup occurs. exact details works rather complicated, fortunately ’s common pattern can use without understanding details. helper function always env argument defaults parent.frame(), pass second argument defer(): Just like .exit() defer(), helper also works within tests: always call helper functions local_; “local” refers fact state change persists locally, lifetime associated function test.","code":"local_digits <- function(sig_digits) { op <- options(digits = sig_digits) on.exit(options(op), add = TRUE, after = FALSE) } neater <- function(x, sig_digits) { local_digits(1) print(x) } neater(pi) #> [1] 3.141593 local_digits <- function(sig_digits, env = parent.frame()) { op <- options(digits = sig_digits) withr::defer(options(op), env) } neater(pi) #> [1] 3 test_that(\"withr lets us write custom helpers for local state manipulation\", { local_digits(1) expect_output(print(exp(1)), \"3\") local_digits(3) expect_output(print(exp(1)), \"2.72\") }) #> Test passed print(exp(1)) #> [1] 2.718282"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"pre-existing-helpers","dir":"Articles","previous_headings":"Foundations","what":"Pre-existing helpers","title":"Test fixtures","text":"write helper function, make sure check wide range local functions already provided withr: can use withr::local_options() write yet another version neater(): local_*() function companion with_() function, nod (), inspiration withr’s name. won’t use with_*() functions , can learn withr.r-lib.org.","code":"neatest <- function(x, sig_digits) { withr::local_options(list(digits = sig_digits)) print(x) } neatest(pi, 3) #> [1] 3.14"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"test-fixtures","dir":"Articles","previous_headings":"","what":"Test fixtures","title":"Test fixtures","text":"Testing often demonstrated cute little tests functions inputs expected results can inlined. real packages, things aren’t always simple functions often depend global state. example, take variant message() shows message verbose option TRUE. test setting option indeed silence message? cases, ’s possible make global state explicit argument function. example, refactor message2() make verbosity explicit argument: Making external state explicit often worthwhile, makes clear exactly inputs determine outputs function. ’s simply possible many cases. ’s test fixtures come : allow temporarily change global state order test function. Test fixture pre-existing term software engineering world (beyond): test fixture something used consistently test item, device, piece software. — Wikipedia test fixture just local_ function use change state way can reach inside test parts code otherwise challenging. example, ’s use withr::local_options() test fixture test message2():","code":"message2 <- function(...) { if (!isTRUE(getOption(\"verbose\"))) { return() } message(...) } message3 <- function(..., verbose = getOption(\"verbose\")) { if (!isTRUE(verbose)) { return() } message(...) } test_that(\"message2() output depends on verbose option\", { withr::local_options(verbose = TRUE) expect_message(message2(\"Hi!\")) withr::local_options(verbose = FALSE) expect_message(message2(\"Hi!\"), NA) }) #> now dyn.load(\"/home/runner/work/_temp/Library/ellipsis/libs/ellipsis.so\") ... #> now dyn.load(\"/home/runner/work/_temp/Library/fansi/libs/fansi.so\") ... #> now dyn.load(\"/home/runner/work/_temp/Library/utf8/libs/utf8.so\") ... #> Test passed"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"case-study-usethis","dir":"Articles","previous_headings":"Test fixtures","what":"Case study: usethis","title":"Test fixtures","text":"One place use test fixtures extensively usethis package (usethis.r-lib.org), provides functions looking files folders R projects, especially packages. Many functions make sense context package, means test , also working inside R package. need way quickly spin minimal package temporary directory, test functions , destroy . solve problem create test fixture, place R/test-helpers.R ’s ’s available testing interactive experimentation: Note cleanup automatically unfolds opposite order setup. Setup , B, C; cleanup -C, -B, -. important must create directory dir can make working directory; must restore original working directory can delete dir; can’t delete dir ’s still working directory! local_create_package() used 170 tests. ’s one example checks usethis::use_roxygen_md() setup necessary use roxygen2 package, markdown support turned . 3 expectations consult DESCRIPTION file, directly indirectly. ’s convenient local_create_package() creates minimal package, valid DESCRIPTION file, us test . test done — poof! — package gone.","code":"local_create_package <- function(dir = file_temp(), env = parent.frame()) { old_project <- proj_get_() # create new folder and package create_package(dir, open = FALSE) # A withr::defer(fs::dir_delete(dir), envir = env) # -A # change working directory setwd(dir) # B withr::defer(setwd(old_project), envir = env) # -B # switch to new usethis project proj_set(dir) # C withr::defer(proj_set(old_project, force = TRUE), envir = env) # -C dir } test_that(\"use_roxygen_md() adds DESCRIPTION fields\", { pkg <- local_create_package() use_roxygen_md() expect_true(uses_roxygen_md()) expect_equal(desc::desc_get(\"Roxygen\", pkg)[[1]], \"list(markdown = TRUE)\")) expect_true(desc::desc_has_fields(\"RoxygenNote\", pkg)) })"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"scope","dir":"Articles","previous_headings":"","what":"Scope","title":"Test fixtures","text":"far applied test fixture individual tests, ’s also possible apply file package.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"file","dir":"Articles","previous_headings":"Scope","what":"File","title":"Test fixtures","text":"move local_() call outside test_that() block, affect tests come . means calling test fixture top file can change behaviour tests. advantages disadvantages: otherwise called fixture every test, ’ve saved bunch work duplicate code. downside, test fails want recreate failure interactive environment can debug, need remember run setup code top file first. Generally, think ’s better copy paste test fixtures across many tests — sure, adds duplication code, makes debugging test failures much easier.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"package","dir":"Articles","previous_headings":"Scope","what":"Package","title":"Test fixtures","text":"run code test run, can create file called tests/testthat/setup.R. code file needs clean , can use special teardown_env(): Setup code typically best used create external resources needed many tests. ’s best kept minimum manually run interactively debugging tests.","code":"# Run before any test write.csv(\"mtcars.csv\", mtcars) # Run after all tests withr::defer(unlink(\"mtcars.csv\"), teardown_env())"},{"path":"https://testthat.r-lib.org/dev/articles/test-fixtures.html","id":"other-challenges","dir":"Articles","previous_headings":"","what":"Other challenges","title":"Test fixtures","text":"collection miscellaneous problems don’t know else describe: base functions hard test depend state can’t control. One example interactive(): ’s way write test fixture allows pretend interactive either TRUE FALSE. now usually use rlang::is_interactive() can controlled rlang_interactive option. ’re using test fixture function, careful return. example, write function dir <- create_local_package() shouldn’t return dir, function returns directory longer exist.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"activating","dir":"Articles","previous_headings":"","what":"Activating","title":"testthat 3e","text":"usual way activate 3rd edition add line DESCRIPTION: activate 3rd edition every test package. can also control edition used individual tests testthat::local_edition(): also useful ’ve switched 3rd edition couple tests fail. can use local_edition(2) revert back old behaviour, giving breathing room figure underlying issue.","code":"Config/testthat/edition: 3 test_that(\"I can use the 3rd edition\", { local_edition(3) expect_true(TRUE) }) #> Test passed test_that(\"I want to use the 2nd edition\", { local_edition(2) expect_true(TRUE) }) #> Test passed"},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"changes","dir":"Articles","previous_headings":"","what":"Changes","title":"testthat 3e","text":"three major changes 3rd edition: number outdated functions now deprecated, ’ll warned every time run tests (won’t cause R CMD check fail). testthat longer silently swallows messages; now need deliberately handle . expect_equal() expect_identical() now use waldo package instead identical() .equal(). makes consistent provides enhanced display differences test fails.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"deprecations","dir":"Articles","previous_headings":"Changes","what":"Deprecations","title":"testthat 3e","text":"number outdated functions deprecated. functions recommended number years, introduction edition idea, didn’t good way preventing people using without breaking lot code CRAN. context() formally deprecated. testthat moving away context() favour file names quite time, now ’ll strongly encouraged remove calls tests. expect_is() deprecated favour specific expect_type(), expect_s3_class(), expect_s4_class(). ensures check expected class along expected OO system. old expect_that() syntax now deprecated. overly clever API regretted even release testthat 1.0.0. expect_equivalent() deprecated since now equivalent (HA HA) expect_equal(ignore_attr = TRUE). main difference won’t ignore names; ’ll need explicit unname() deliberately want ignore names. setup() teardown() deprecated favour test fixtures. See vignette(\"test-fixtures\") details. expect_known_output(), expect_known_value(), expect_known_hash(), expect_equal_to_reference() deprecated favour expect_snapshot_output() expect_snapshot_value(). with_mock() local_mock() deprecated; please use with_mocked_bindings() local_mocked_bindings() instead. Fixing deprecation warnings straightforward.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"warnings","dir":"Articles","previous_headings":"Changes","what":"Warnings","title":"testthat 3e","text":"second edition, expect_warning() swallows warnings regardless whether match regexp class: third edition, expect_warning() captures one warning others bubble : can either add additional expectations catch warnings, silence suppressWarnings(): Alternatively, might want capture snapshot test: principle also applies expect_message(), message handling changed radical way, described next.","code":"f <- function() { warning(\"First warning\") warning(\"Second warning\") warning(\"Third warning\") } local_edition(2) expect_warning(f(), \"First\") local_edition(3) expect_warning(f(), \"First\") #> Warning in f(): Second warning #> Warning in f(): Third warning f() %>% expect_warning(\"First\") %>% expect_warning(\"Second\") %>% expect_warning(\"Third\") f() %>% expect_warning(\"First\") %>% suppressWarnings() test_that(\"f() produces expected outputs/messages/warnings\", { expect_snapshot(f()) }) #> Can't compare snapshot to reference when testing interactively. #> i Run `devtools::test()` or `testthat::test_file()` to see changes. #> Current value: #> Code #> f() #> Condition #> Warning in `f()`: #> First warning #> Warning in `f()`: #> Second warning #> Warning in `f()`: #> Third warning #> -- Skip: f() produces expected outputs/messages/warnings ----------------------- #> Reason: empty test"},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"messages","dir":"Articles","previous_headings":"Changes","what":"Messages","title":"testthat 3e","text":"reasons can longer remember, testthat silently ignores messages. inconsistent types output, 3rd edition, now bubble test results. ’ll explicit ignore suppressMessages(), ’re important, test presence expect_message().","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"waldo","dir":"Articles","previous_headings":"Changes","what":"waldo","title":"testthat 3e","text":"Probably biggest day--day difference (biggest reason upgrade!) use waldo::compare() inside expect_equal() expect_identical(). goal waldo find concisely describe difference pair R objects, ’s designed specifically help figure ’s gone wrong unit tests. waldo looks even better console carefully uses colours help highlight differences. use waldo also makes precise difference expect_equal() expect_identical(): expect_equal() sets tolerance waldo ignore small numerical differences arising floating point computation. Otherwise functions identical (HA HA). change likely result work upgrade, waldo can give slightly different results identical() .equal() moderately common situations. believe whole differences meaningful useful, ’ll need handle tweaking tests. following changes likely affect : expect_equal() previously ignored environments formulas functions. like arise testing models. ’s worth thinking correct values , annoying can opt comparison ignore_function_env ignore_formula_env. expect_equal() used combination .equal() home-grown testthat::compare() unfortunately used slightly different definition tolerance. Now expect_equal() always uses definition tolerance everywhere, may require tweaks exising tolerance values. expect_equal() previously ignored timezone differences one object current timezone set implicitly (\"\") set explicitly:","code":"f1 <- factor(letters[1:3]) f2 <- ordered(letters[1:3], levels = letters[1:4]) local_edition(2) expect_equal(f1, f2) #> Error: `f1` not equal to `f2`. #> Attributes: < Component \"class\": Lengths (1, 2) differ (string compare on first 1) > #> Attributes: < Component \"class\": 1 string mismatch > #> Attributes: < Component \"levels\": Lengths (3, 4) differ (string compare on first 3) > local_edition(3) expect_equal(f1, f2) #> Error: `f1` (`actual`) not equal to `f2` (`expected`). #> #> `class(actual)`: \"factor\" #> `class(expected)`: \"ordered\" \"factor\" #> #> `levels(actual)`: \"a\" \"b\" \"c\" #> `levels(expected)`: \"a\" \"b\" \"c\" \"d\" dt1 <- dt2 <- ISOdatetime(2020, 1, 2, 3, 4, 0) attr(dt1, \"tzone\") <- \"\" attr(dt2, \"tzone\") <- Sys.timezone() local_edition(2) expect_equal(dt1, dt2) local_edition(3) expect_equal(dt1, dt2) #> Error: `dt1` (`actual`) not equal to `dt2` (`expected`). #> #> `attr(actual, 'tzone')`: \"\" #> `attr(expected, 'tzone')`: \"UTC\""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"reproducible-output","dir":"Articles","previous_headings":"Changes","what":"Reproducible output","title":"testthat 3e","text":"third edition, test_that() automatically calls local_reproducible_output() automatically sets number options environment variables ensure output reproducible across systems. includes setting: options(crayon.enabled = FALSE) options(cli.unicode = FALSE) crayon cli packages produce raw ASCII output. Sys.setLocale(\"LC_COLLATE\" = \"C\") sorting character vector returns order regardless system language. options(width = 80) print methods always generate output regardless actual console width. See documentation details.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"upgrading","dir":"Articles","previous_headings":"","what":"Upgrading","title":"testthat 3e","text":"changes lend following workflow upgrading 2nd 3rd edition: Activate edition 3. can let usethis::use_testthat(3) . Remove replace deprecated functions, going list . output got noisy, quiet things either capturing suppressing warnings messages. Inspect test outputs objects “equal” anymore.","code":""},{"path":"https://testthat.r-lib.org/dev/articles/third-edition.html","id":"alternatives","dir":"Articles","previous_headings":"","what":"Alternatives","title":"testthat 3e","text":"might wonder came idea “edition”, rather creating new package like testthat3. decided making new package 2nd 3rd edition share large amount code, making new package substantially increased maintenance burden: majority bugs ’ve needed fixed two places. ’re programmer languages, might wonder can’t rely semantic versioning. main reason CRAN checks packages use testthat latest version testthat, simply incrementing major version number doesn’t actually help reducing R CMD check failures CRAN.","code":""},{"path":"https://testthat.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Hadley Wickham. Author, maintainer. . Copyright holder, funder. R Core team. Contributor. Implementation utils::recover()","code":""},{"path":"https://testthat.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Wickham H (2011). “testthat: Get Started Testing.” R Journal, 3, 5–10. https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf.","code":"@Article{, author = {Hadley Wickham}, title = {testthat: Get Started with Testing}, journal = {The R Journal}, year = {2011}, volume = {3}, pages = {5--10}, url = {https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf}, }"},{"path":[]},{"path":"https://testthat.r-lib.org/dev/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Unit Testing for R","text":"Testing code can painful tedious, greatly increases quality code. testthat tries make testing fun possible, get visceral satisfaction writing tests. Testing addictive, time. make happen, testthat: Provides functions make easy describe expect function , including catching errors, warnings, messages. Easily integrates existing workflow, whether ’s informal testing command line, building test suites, using R CMD check. Displays test progress visually, showing pass, fail, error every expectation. ’re using terminal recent version RStudio, ’ll even colour output. testthat draws inspiration xUnit family testing packages, well many innovative ruby testing libraries, like rspec, testy, bacon cucumber. testthat popular unit testing package R used thousands CRAN packages. ’re familiar testthat, testing chapter R packages gives good overview, along workflow advice concrete examples.","code":""},{"path":"https://testthat.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Unit Testing for R","text":"","code":"# Install the released version from CRAN install.packages(\"testthat\") # Or the development version from GitHub: # install.packages(\"pak\") pak::pak(\"r-lib/testthat\")"},{"path":"https://testthat.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"Unit Testing for R","text":"easiest way get started usethis. Assuming ’re package directory, just run usethis::use_test(\"name\") create test file, set infrastructure need. ’re using RStudio, press Cmd/Ctrl + Shift + T (run devtools::test() ) run tests package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/CheckReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Check reporter: 13 line summary of problems — CheckReporter","title":"Check reporter: 13 line summary of problems — CheckReporter","text":"R CMD check displays last 13 lines result, report designed ensure see something useful .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/DebugReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: start recovery. — DebugReporter","title":"Test reporter: start recovery. — DebugReporter","text":"reporter call modified version recover() broken expectations.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/FailReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: fail at end. — FailReporter","title":"Test reporter: fail at end. — FailReporter","text":"reporter simply throw error tests failed. best combined another reporter, SummaryReporter.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/JunitReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: summary of errors in jUnit XML format. — JunitReporter","title":"Test reporter: summary of errors in jUnit XML format. — JunitReporter","text":"reporter includes detailed results test summaries, written file (stdout) jUnit XML format. can read Jenkins Continuous Integration System report dashboard etc. Requires xml2 package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/JunitReporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Test reporter: summary of errors in jUnit XML format. — JunitReporter","text":"fit jUnit structure, context() becomes name well base classname. test_that() name becomes rest classname. deparsed expect_that() call becomes name. failure, message goes node message argument (first line ) text content (full message). Execution time details also recorded. References jUnit XML format: http://llg.cubic.org/docs/junit/","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/ListReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"List reporter: gather all test results along with elapsed time and\nfile information. — ListReporter","title":"List reporter: gather all test results along with elapsed time and\nfile information. — ListReporter","text":"reporter gathers results, adding additional information test elapsed time, test filename available. useful reporting.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/LocationReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: location — LocationReporter","title":"Test reporter: location — LocationReporter","text":"reporter simply prints location every expectation error. useful trying figure source segfault, want figure code triggers C/C++ breakpoint","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/MinimalReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: minimal. — MinimalReporter","title":"Test reporter: minimal. — MinimalReporter","text":"minimal test reporter provides absolutely minimum amount information: whether expectation succeeded, failed experienced error. want find failures errors actually , need run informative test reporter.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/MultiReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Multi reporter: combine several reporters in one. — MultiReporter","title":"Multi reporter: combine several reporters in one. — MultiReporter","text":"reporter useful use several reporters time, e.g. adding custom reporter without removing current one.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/ProgressReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: interactive progress bar of errors. — ProgressReporter","title":"Test reporter: interactive progress bar of errors. — ProgressReporter","text":"ProgressReporter designed interactive use. goal give actionable insights help understand status code. reporter also praises time--time tests pass. default reporter test_dir(). ParallelProgressReporter similar ProgressReporter, works better packages want parallel tests. CompactProgressReporter minimal version ProgressReporter designed use single files. default reporter test_file().","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/RStudioReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: RStudio — RStudioReporter","title":"Test reporter: RStudio — RStudioReporter","text":"reporter designed output RStudio. produces results easily parsed form.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/Reporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Manage test reporting — Reporter","title":"Manage test reporting — Reporter","text":"job reporter aggregate results files, tests, expectations display informative way. Every testtthat function runs multiple tests provides reporter argument can use override default (selected default_reporter()).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/Reporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Manage test reporting — Reporter","text":"need use Reporter object directly creating new reporter. Currently, creating new Reporters undocumented, want create , need make sure familiar R6 need read source code .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/Reporter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Manage test reporting — Reporter","text":"","code":"path <- testthat_example(\"success\") test_file(path) #> #> ══ Testing test-success.R ════════════════════════════════════════════════ #> #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] #> [ FAIL 0 | WARN 0 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 2 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 3 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] #> #> ── Warning (test-success.R:10:3): some tests have warnings ───────────────────── #> NaNs produced #> Backtrace: #> ▆ #> 1. └─testthat::expect_equal(log(-1), NaN) at test-success.R:10:3 #> 2. └─testthat::quasi_label(enquo(object), label, arg = \"object\") #> 3. └─rlang::eval_bare(expr, quo_get_env(quo)) #> #> ── Skipped tests (1) ───────────────────────────────────────────────────── #> • This test hasn't been written yet (1): test-success.R:6:3 #> #> #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] # Override the default by supplying the name of a reporter test_file(path, reporter = \"minimal\") #> .SW..."},{"path":"https://testthat.r-lib.org/dev/reference/SilentReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: gather all errors silently. — SilentReporter","title":"Test reporter: gather all errors silently. — SilentReporter","text":"reporter quietly runs tests, simply gathering expectations. helpful programmatically inspecting errors test run. can retrieve results expectations() method.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/StopReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: stop on error — StopReporter","title":"Test reporter: stop on error — StopReporter","text":"default reporter used expect_that() run interactively. responds stop()ping failures nothing otherwise. ensure failing test raise error.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/StopReporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Test reporter: stop on error — StopReporter","text":"used quick dirty test, final automated testing R CMD check. Otherwise, use reporter runs tests gives context problem.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/SummaryReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: summary of errors. — SummaryReporter","title":"Test reporter: summary of errors. — SummaryReporter","text":"reporter designed interactive usage: lets know tests run successfully well fully reporting information failures errors.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/SummaryReporter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Test reporter: summary of errors. — SummaryReporter","text":"can use max_reports field control maximum number detailed reports produced reporter. useful running auto_test() additional benefit, reporter praise time--time tests pass.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/TapReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: TAP format. — TapReporter","title":"Test reporter: TAP format. — TapReporter","text":"reporter output results Test Anything Protocol (TAP), simple text-based interface testing modules test harness. information TAP, see http://testanything.org","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/TeamcityReporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Test reporter: Teamcity format. — TeamcityReporter","title":"Test reporter: Teamcity format. — TeamcityReporter","text":"reporter output results Teamcity message format. information Teamcity messages, see http://confluence.jetbrains.com/display/TCD7/Build+Script+Interaction++TeamCity","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":null,"dir":"Reference","previous_headings":"","what":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"idea behind auto_test() just leave running develop code. Every time save file automatically tested can easily see changes caused test failures.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"","code":"auto_test( code_path, test_path, reporter = default_reporter(), env = test_env(), hash = TRUE )"},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"code_path path directory containing code test_path path directory containing tests reporter test reporter use env environment execute test suite. hash Passed watch(). FALSE, uses less accurate modification time stamps, faster large files.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/auto_test.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Watches code and tests for changes, rerunning tests as appropriate. — auto_test","text":"current strategy rerunning tests follows: code changed, files reloaded tests rerun otherwise, new modified test run future, auto_test() might implement one following intelligent alternatives: Use codetools build dependency tree rerun tests dependency changes. Mimic ruby's autotest rerun failing tests pass, rerun tests.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/auto_test_package.html","id":null,"dir":"Reference","previous_headings":"","what":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","title":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","text":"Watches package changes, rerunning tests appropriate.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/auto_test_package.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","text":"","code":"auto_test_package(pkg = \".\", reporter = default_reporter(), hash = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/auto_test_package.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Watches a package for changes, rerunning tests as appropriate. — auto_test_package","text":"pkg path package reporter test reporter use hash Passed watch(). FALSE, uses less accurate modification time stamps, faster large files.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":null,"dir":"Reference","previous_headings":"","what":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"functions allow capture side-effects function call including printed output, messages warnings. longer recommend use functions, instead relying expect_message() friends bubble unmatched conditions. just want silence unimportant warnings, use suppressWarnings().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"","code":"capture_condition(code, entrace = FALSE) capture_error(code, entrace = FALSE) capture_expectation(code, entrace = FALSE) capture_message(code, entrace = FALSE) capture_warning(code, entrace = FALSE) capture_messages(code) capture_warnings(code, ignore_deprecation = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"code Code evaluate entrace Whether add backtrace captured condition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"Singular functions (capture_condition, capture_expectation etc) return condition object. capture_messages() capture_warnings return character vector message text.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_condition.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Capture conditions, including messages, warnings, expectations, and errors. — capture_condition","text":"","code":"f <- function() { message(\"First\") warning(\"Second\") message(\"Third\") } capture_message(f()) #> > capture_messages(f()) #> Warning: Second #> [1] \"First\\n\" \"Third\\n\" capture_warning(f()) #> First #> capture_warnings(f()) #> First #> Third #> [1] \"Second\" # Condition will capture anything capture_condition(f()) #> >"},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Capture output to console — capture_output","title":"Capture output to console — capture_output","text":"Evaluates code special context output captured, similar capture.output().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Capture output to console — capture_output","text":"","code":"capture_output(code, print = FALSE, width = 80) capture_output_lines(code, print = FALSE, width = 80) testthat_print(x)"},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Capture output to console — capture_output","text":"code Code evaluate. print TRUE result evaluating code visible, print result using testthat_print(). width Number characters per line output. inherit getOption(\"width\") tests always use output width, minimising spurious differences.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Capture output to console — capture_output","text":"capture_output() returns single string. capture_output_lines() returns character vector one entry line","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Capture output to console — capture_output","text":"Results printed using testthat_print() generic, defaults print(), giving ability customise printing object tests, needed.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/capture_output.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Capture output to console — capture_output","text":"","code":"capture_output({ cat(\"Hi!\\n\") cat(\"Bye\\n\") }) #> [1] \"Hi!\\nBye\" capture_output_lines({ cat(\"Hi!\\n\") cat(\"Bye\\n\") }) #> [1] \"Hi!\" \"Bye\" capture_output(\"Hi\") #> [1] \"\" capture_output(\"Hi\", print = TRUE) #> [1] \"[1] \\\"Hi\\\"\""},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":null,"dir":"Reference","previous_headings":"","what":"Provide human-readable comparison of two objects — compare","title":"Provide human-readable comparison of two objects — compare","text":"compare similar base::.equal(), somewhat buggy use tolerance. Please use waldo instead.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Provide human-readable comparison of two objects — compare","text":"","code":"compare(x, y, ...) # S3 method for default compare(x, y, ..., max_diffs = 9) # S3 method for character compare( x, y, check.attributes = TRUE, ..., max_diffs = 5, max_lines = 5, width = cli::console_width() ) # S3 method for numeric compare( x, y, tolerance = testthat_tolerance(), check.attributes = TRUE, ..., max_diffs = 9 ) # S3 method for POSIXt compare(x, y, tolerance = 0.001, ..., max_diffs = 9)"},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Provide human-readable comparison of two objects — compare","text":"x, y Objects compare ... Additional arguments used control specifics comparison max_diffs Maximum number differences show check.attributes TRUE, also checks values attributes. max_lines Maximum number lines show difference width Width output device tolerance Numerical tolerance: differences (sense base::.equal()) smaller value ignored. default tolerance sqrt(.Machine$double.eps), unless long doubles available, case test skipped.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Provide human-readable comparison of two objects — compare","text":"","code":"# Character ----------------------------------------------------------------- x <- c(\"abc\", \"def\", \"jih\") compare(x, x) #> Equal y <- paste0(x, \"y\") compare(x, y) #> 3/3 mismatches #> x[1]: \"abc\" #> y[1]: \"abcy\" #> #> x[2]: \"def\" #> y[2]: \"defy\" #> #> x[3]: \"jih\" #> y[3]: \"jihy\" compare(letters, paste0(letters, \"-\")) #> 26/26 mismatches #> x[1]: \"a\" #> y[1]: \"a-\" #> #> x[2]: \"b\" #> y[2]: \"b-\" #> #> x[3]: \"c\" #> y[3]: \"c-\" #> #> x[4]: \"d\" #> y[4]: \"d-\" #> #> x[5]: \"e\" #> y[5]: \"e-\" x <- \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursus tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi non, pulvinar dolor. Donec pretium iaculis nulla, ut interdum sapien ultricies a. \" y <- \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursus tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi non, pulvinar dolor. Donec pretium iaculis nulla, ut interdum sapien ultricies a. \" compare(x, y) #> 1/1 mismatches #> x[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> x[1]: s\\n tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi n #> x[1]: on, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapie #> x[1]: n ultricies a. \" #> y[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> y[1]: s\\n tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi #> y[1]: non, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapi #> y[1]: en ultricies a. \" compare(c(x, x), c(y, y)) #> 2/2 mismatches #> x[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> x[1]: s\\n tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi n #> x[1]: on, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapie #> x[1]: n ultricies a. \" #> y[1]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> y[1]: s\\n tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi #> y[1]: non, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapi #> y[1]: en ultricies a. \" #> #> x[2]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> x[2]: s\\n tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi n #> x[2]: on, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapie #> x[2]: n ultricies a. \" #> y[2]: \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursu #> y[2]: s\\n tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi #> y[2]: non, pulvinar\\n dolor. Donec pretium iaculis nulla, ut interdum sapi #> y[2]: en ultricies a. \" # Numeric ------------------------------------------------------------------- x <- y <- runif(100) y[sample(100, 10)] <- 5 compare(x, y) #> 10/100 mismatches (average diff: 4.42) #> [13] 0.643 - 5 == -4.36 #> [14] 0.661 - 5 == -4.34 #> [18] 0.814 - 5 == -4.19 #> [25] 0.607 - 5 == -4.39 #> [47] 0.999 - 5 == -4.00 #> [54] 0.806 - 5 == -4.19 #> [64] 0.968 - 5 == -4.03 #> [79] 0.039 - 5 == -4.96 #> [83] 0.144 - 5 == -4.86 #> ... x <- y <- 1:10 x[5] <- NA x[6] <- 6.5 compare(x, y) #> 2/10 mismatches (average diff: 0.5) #> [5] NA - 5 == NA #> [6] 6.5 - 6 == 0.5 # Compare ignores minor numeric differences in the same way # as all.equal. compare(x, x + 1e-9) #> Equal"},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":null,"dir":"Reference","previous_headings":"","what":"Compare two directory states. — compare_state","title":"Compare two directory states. — compare_state","text":"Compare two directory states.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compare two directory states. — compare_state","text":"","code":"compare_state(old, new)"},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compare two directory states. — compare_state","text":"old previous state new current state","code":""},{"path":"https://testthat.r-lib.org/dev/reference/compare_state.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compare two directory states. — compare_state","text":"list containing number changes files added, deleted modified","code":""},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a number greater/less than the expected value? — comparison-expectations","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"code return number greater/less expected value?","code":""},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"","code":"expect_lt(object, expected, label = NULL, expected.label = NULL) expect_lte(object, expected, label = NULL, expected.label = NULL) expect_gt(object, expected, label = NULL, expected.label = NULL) expect_gte(object, expected, label = NULL, expected.label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"object, expected value compare expected bound. label, expected.label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/comparison-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a number greater/less than the expected value? — comparison-expectations","text":"","code":"a <- 9 expect_lt(a, 10) if (FALSE) { expect_lt(11, 10) } a <- 11 expect_gt(a, 10) if (FALSE) { expect_gt(9, 10) }"},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":null,"dir":"Reference","previous_headings":"","what":"Describe the context of a set of tests. — context","title":"Describe the context of a set of tests. — context","text":"Use context() longer recommended. Instead omit , messages use name file instead. ensures context test file name always sync. context defines set tests test related functionality. Usually one context per file, may multiple contexts single file choose.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Describe the context of a set of tests. — context","text":"","code":"context(desc)"},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Describe the context of a set of tests. — context","text":"desc description context. start capital letter.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Describe the context of a set of tests. — context","text":"context() deprecated third edition, equivalent information instead recorded test file name.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Describe the context of a set of tests. — context","text":"","code":"context(\"String processing\") #> Warning: `context()` was deprecated in the 3rd edition. context(\"Remote procedure calls\") #> Warning: `context()` was deprecated in the 3rd edition."},{"path":"https://testthat.r-lib.org/dev/reference/context_start_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Start test context from a file name — context_start_file","title":"Start test context from a file name — context_start_file","text":"use external reporters","code":""},{"path":"https://testthat.r-lib.org/dev/reference/context_start_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Start test context from a file name — context_start_file","text":"","code":"context_start_file(name)"},{"path":"https://testthat.r-lib.org/dev/reference/context_start_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Start test context from a file name — context_start_file","text":"name file name","code":""},{"path":"https://testthat.r-lib.org/dev/reference/default_reporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve the default reporter — default_reporter","title":"Retrieve the default reporter — default_reporter","text":"defaults : ProgressReporter interactive, non-parallel; override testthat.default_reporter ParallelProgressReporter interactive, parallel packages; override testthat.default_parallel_reporter CompactProgressReporter single-file interactive; override testthat.default_compact_reporter CheckReporter R CMD check; override testthat.default_check_reporter","code":""},{"path":"https://testthat.r-lib.org/dev/reference/default_reporter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve the default reporter — default_reporter","text":"","code":"default_reporter() default_parallel_reporter() default_compact_reporter() check_reporter()"},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":null,"dir":"Reference","previous_headings":"","what":"describe: a BDD testing language — describe","title":"describe: a BDD testing language — describe","text":"simple BDD DSL writing tests. language similar RSpec Ruby Mocha JavaScript. BDD tests read like sentences thus easier understand specification function/component .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"describe: a BDD testing language — describe","text":"","code":"describe(description, code) it(description, code = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"describe: a BDD testing language — describe","text":"description description feature code test code containing specs","code":""},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"describe: a BDD testing language — describe","text":"Tests using describe syntax verify tested code, also document intended behaviour. describe block specifies larger component function contains set specifications. specification defined block. block functions test evaluated environment. can also nested describe blocks. test syntax helps test intended behaviour code. example: want write new function package. Try describe specification first using describe, write code. , start implement tests specification (.e. block). Use describe verify implement right things use test_that() ensure things right.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/describe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"describe: a BDD testing language — describe","text":"","code":"describe(\"matrix()\", { it(\"can be multiplied by a scalar\", { m1 <- matrix(1:4, 2, 2) m2 <- m1 * 2 expect_equal(matrix(1:4 * 2, 2, 2), m2) }) it(\"can have not yet tested specs\") }) #> Test passed #> Test passed # Nested specs: ## code addition <- function(a, b) a + b division <- function(a, b) a / b ## specs describe(\"math library\", { describe(\"addition()\", { it(\"can add two numbers\", { expect_equal(1 + 1, addition(1, 1)) }) }) describe(\"division()\", { it(\"can divide two numbers\", { expect_equal(10 / 2, division(10, 2)) }) it(\"can handle division by 0\") #not yet implemented }) }) #> Test passed #> Test passed #> Test passed"},{"path":"https://testthat.r-lib.org/dev/reference/dir_state.html","id":null,"dir":"Reference","previous_headings":"","what":"Capture the state of a directory. — dir_state","title":"Capture the state of a directory. — dir_state","text":"Capture state directory.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/dir_state.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Capture the state of a directory. — dir_state","text":"","code":"dir_state(path, pattern = NULL, hash = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/dir_state.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Capture the state of a directory. — dir_state","text":"path path directory pattern regular expression filter files hash use hash (slow accurate) time stamp (fast less accurate)","code":""},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return the expected value? — equality-expectations","title":"Does code return the expected value? — equality-expectations","text":"functions provide two levels strictness comparing computation reference value. expect_identical() baseline; expect_equal() relaxes test ignore small numeric differences. 2nd edition, expect_identical() uses identical() expect_equal uses .equal(). 3rd edition, functions use waldo. differ expect_equal() sets tolerance = testthat_tolerance() small floating point differences ignored; also implies (e.g.) 1 1L treated equal.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return the expected value? — equality-expectations","text":"","code":"expect_equal( object, expected, ..., tolerance = if (edition_get() >= 3) testthat_tolerance(), info = NULL, label = NULL, expected.label = NULL ) expect_identical( object, expected, info = NULL, label = NULL, expected.label = NULL, ... )"},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return the expected value? — equality-expectations","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ... 3e: passed waldo::compare(). See docs see ways control comparison. 2e: passed compare()/identical(). tolerance 3e: passed waldo::compare(). non-NULL, ignore small floating point differences. uses algorithm .equal() tolerance usually relative (.e. mean(abs(x - y) / mean(abs(y)) < tolerance), except differences small, becomes absolute (.e. mean(abs(x - y) < tolerance). See waldo documentation details. 2e: passed compare(), set. hard reason exactly tolerance means depending precise code path either absolute relative tolerance. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label, expected.label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/equality-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return the expected value? — equality-expectations","text":"","code":"a <- 10 expect_equal(a, 10) # Use expect_equal() when testing for numeric equality if (FALSE) { expect_identical(sqrt(2) ^ 2, 2) } expect_equal(sqrt(2) ^ 2, 2)"},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":null,"dir":"Reference","previous_headings":"","what":"Evaluate a promise, capturing all types of output. — evaluate_promise","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"Evaluate promise, capturing types output.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"","code":"evaluate_promise(code, print = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"code Code evaluate.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"list containing result result function output string containing output function warnings character vector containing text warning messages character vector containing text message","code":""},{"path":"https://testthat.r-lib.org/dev/reference/evaluate_promise.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Evaluate a promise, capturing all types of output. — evaluate_promise","text":"","code":"evaluate_promise({ print(\"1\") message(\"2\") warning(\"3\") 4 }) #> $result #> [1] 4 #> #> $output #> [1] \"[1] \\\"1\\\"\" #> #> $warnings #> [1] \"3\" #> #> $messages #> [1] \"2\\n\" #>"},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":null,"dir":"Reference","previous_headings":"","what":"The building block of all expect_ functions — expect","title":"The building block of all expect_ functions — expect","text":"Call expect() writing expectations. See vignette(\"custom-expectation\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The building block of all expect_ functions — expect","text":"","code":"expect( ok, failure_message, info = NULL, srcref = NULL, trace = NULL, trace_env = caller_env() )"},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The building block of all expect_ functions — expect","text":"ok TRUE FALSE indicating expectation successful. failure_message Message show expectation failed. info Character vector continuing additional information. Included backward compatibility new expectations use . srcref Location failure. needed explicitly supplied need forward srcref captured elsewhere. trace optional backtrace created rlang::trace_back(). supplied, expectation displayed backtrace. trace_env .null(trace), used automatically generate traceback running test_code()/test_file() trace_env. generally need set wrapping expectation inside another function.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"The building block of all expect_ functions — expect","text":"expectation object. Signals expectation condition continue_test restart.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"The building block of all expect_ functions — expect","text":"expect() creates signals expectation one go, exp_signal() separately signals expectation manually created new_expectation(). Expectations signalled following protocol: expectation failure error, signalled base::stop(). Otherwise, signalled base::signalCondition(). continue_test restart registered. invoked, failing expectations ignored normal control flow resumed run tests.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":null,"dir":"Reference","previous_headings":"","what":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"Compares object expected using .equal() check.attributes = FALSE.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"","code":"expect_equivalent( object, expected, ..., info = NULL, label = NULL, expected.label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ... Passed compare(). info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label, expected.label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"expect_equivalent() deprecated 3rd edition. Instead use expect_equal(ignore_attr = TRUE).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_equivalent.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Is an object equal to the expected value, ignoring attributes? — expect_equivalent","text":"","code":"#' # expect_equivalent() ignores attributes a <- b <- 1:3 names(b) <- letters[1:3] if (FALSE) { expect_equal(a, b) } expect_equivalent(a, b) #> Warning: `expect_equivalent()` was deprecated in the 3rd edition. #> ℹ Use expect_equal(ignore_attr = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code throw an error, warning, message, or other condition? — expect_error","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"expect_error(), expect_warning(), expect_message(), expect_condition() check code throws error, warning, message, condition message matches regexp, class inherits class. See details. 3rd edition, functions match () single condition. additional non-matching (regexp class used) conditions bubble outside expectation. additional conditions important need catch additional expect_message()/expect_warning() calls; unimportant can ignore suppressMessages()/suppressWarnings(). can tricky test combination different conditions, message followed error. expect_snapshot() often easier alternative complex cases.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"","code":"expect_error( object, regexp = NULL, class = NULL, ..., inherit = TRUE, info = NULL, label = NULL ) expect_warning( object, regexp = NULL, class = NULL, ..., inherit = TRUE, all = FALSE, info = NULL, label = NULL ) expect_message( object, regexp = NULL, class = NULL, ..., inherit = TRUE, all = FALSE, info = NULL, label = NULL ) expect_condition( object, regexp = NULL, class = NULL, ..., inherit = TRUE, info = NULL, label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. regexp Regular expression test . character vector giving regular expression must match error message. NULL, default, asserts error, test specific value. NA, asserts errors, now recommend using expect_no_error() friends instead. Note use message errors/warnings/messages generate. Avoid tests rely specific text generated another package since can easily change. need test text generated another package, either protect test skip_on_cran() use expect_snapshot(). class Instead supplying regular expression, can also supply class name. useful \"classed\" conditions. ... Arguments passed expect_match fixed TRUE, treats regexp string matched exactly (regular expressions). Overrides perl. perl logical. Perl-compatible regexps used? inherit Whether match regexp class across ancestry chained errors. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use . DEPRECATED need test multiple warnings/messages now need use multiple calls expect_message()/ expect_warning()","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"regexp = NA, value first argument; otherwise captured condition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"testing-message-vs-class","dir":"Reference","previous_headings":"","what":"Testing message vs class","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"checking code generates error, important check error one expect. two ways . first way simplest: just provide regexp match fragment error message. easy, fragile, test fail error message changes (even error). robust way test class error, one. can learn custom conditions https://adv-r.hadley.nz/conditions.html#custom-conditions, short, errors S3 classes can generate custom class check using class instead regexp. using expect_error() check error message formatted way makes sense human, recommend using expect_snapshot() instead.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_error.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code throw an error, warning, message, or other condition? — expect_error","text":"","code":"# Errors ------------------------------------------------------------------ f <- function() stop(\"My error!\") expect_error(f()) expect_error(f(), \"My error!\") # You can use the arguments of grepl to control the matching expect_error(f(), \"my error!\", ignore.case = TRUE) # Note that `expect_error()` returns the error object so you can test # its components if needed err <- expect_error(rlang::abort(\"a\", n = 10)) expect_equal(err$n, 10) # Warnings ------------------------------------------------------------------ f <- function(x) { if (x < 0) { warning(\"*x* is already negative\") return(x) } -x } expect_warning(f(-1)) expect_warning(f(-1), \"already negative\") expect_warning(f(1), NA) # To test message and output, store results to a variable expect_warning(out <- f(-1), \"already negative\") expect_equal(out, -1) # Messages ------------------------------------------------------------------ f <- function(x) { if (x < 0) { message(\"*x* is already negative\") return(x) } -x } expect_message(f(-1)) expect_message(f(-1), \"already negative\") expect_message(f(1), NA)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a visible or invisible object? — expect_invisible","title":"Does code return a visible or invisible object? — expect_invisible","text":"Use test whether function returns visible invisible output. Typically use check functions called primarily side-effects return data argument invisibly.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a visible or invisible object? — expect_invisible","text":"","code":"expect_invisible(call, label = NULL) expect_visible(call, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a visible or invisible object? — expect_invisible","text":"call function call. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code return a visible or invisible object? — expect_invisible","text":"evaluated call, invisibly.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_invisible.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a visible or invisible object? — expect_invisible","text":"","code":"expect_invisible(x <- 10) expect_visible(x) # Typically you'll assign the result of the expectation so you can # also check that the value is as you expect. greet <- function(name) { message(\"Hi \", name) invisible(name) } out <- expect_invisible(greet(\"Hadley\")) #> Hi Hadley expect_equal(out, \"Hadley\")"},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":null,"dir":"Reference","previous_headings":"","what":"Does an object inherit from a given class? — expect_is","title":"Does an object inherit from a given class? — expect_is","text":"expect_is() older form uses inherits() without checking whether x S3, S4, neither. Instead, recommend using expect_type(), expect_s3_class() expect_s4_class() clearly convey intent.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does an object inherit from a given class? — expect_is","text":"","code":"expect_is(object, class, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does an object inherit from a given class? — expect_is","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. class Either character vector class names, expect_s3_class() expect_s4_class(), NA assert object S3 S4 object.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_is.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Does an object inherit from a given class? — expect_is","text":"expect_is() formally deprecated 3rd edition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Expectations: is the output or the value equal to a known good value? — expect_known_output","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"complex printed output objects, often challenging describe exactly expect see. expect_known_value() expect_known_output() provide slightly weaker guarantee, simply asserting values changed since last time ran .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"","code":"expect_known_output( object, file, update = TRUE, ..., info = NULL, label = NULL, print = FALSE, width = 80 ) expect_known_value( object, file, update = TRUE, ..., info = NULL, label = NULL, version = 2 ) expect_known_hash(object, hash = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"file File path known value/output stored. update file updated? Defaults TRUE, expectation notice changes first failure, see modified files git. ... Passed waldo::compare(). info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. print TRUE result evaluating code visible, print result using testthat_print(). width Number characters per line output. inherit getOption(\"width\") tests always use output width, minimising spurious differences. version serialization format version use. default, 2, default format R 1.4.0 3.5.3. Version 3 became default R 3.6.0 can read R versions 3.5.0 higher. hash Known hash value. Leave empty informed use test output.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"expectations used conjunction git, otherwise way revert previous values. Git particularly useful conjunction expect_known_output() diffs show exactly changed. Note known values updates updated running tests interactively. R CMD check clones package source changes reference files occur temporary directory, synchronised back source package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"expect_known_output() friends deprecated 3rd edition; please use expect_snapshot_output() friends instead.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_known_output.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Expectations: is the output or the value equal to a known good value? — expect_known_output","text":"","code":"tmp <- tempfile() # The first run always succeeds expect_known_output(mtcars[1:10, ], tmp, print = TRUE) #> Warning: `expect_known_output()` was deprecated in the 3rd edition. #> ℹ Please use `expect_snapshot_output()` instead #> Warning: Creating reference output # Subsequent runs will succeed only if the file is unchanged # This will succeed: expect_known_output(mtcars[1:10, ], tmp, print = TRUE) #> Warning: `expect_known_output()` was deprecated in the 3rd edition. #> ℹ Please use `expect_snapshot_output()` instead if (FALSE) { # This will fail expect_known_output(mtcars[1:9, ], tmp, print = TRUE) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector with the specified length? — expect_length","title":"Does code return a vector with the specified length? — expect_length","text":"code return vector specified length?","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector with the specified length? — expect_length","text":"","code":"expect_length(object, n)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector with the specified length? — expect_length","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. n Expected length.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_length.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector with the specified length? — expect_length","text":"","code":"expect_length(1, 1) expect_length(1:10, 10) if (FALSE) { expect_length(1:10, 1) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_less_than.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated numeric comparison functions — expect_less_than","title":"Deprecated numeric comparison functions — expect_less_than","text":"functions deprecated favour concise expect_gt() expect_lt().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_less_than.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deprecated numeric comparison functions — expect_less_than","text":"","code":"expect_less_than(...) expect_more_than(...)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_less_than.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deprecated numeric comparison functions — expect_less_than","text":"... arguments passed expect_lt()/expect_gt().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":null,"dir":"Reference","previous_headings":"","what":"Does a string match a regular expression? — expect_match","title":"Does a string match a regular expression? — expect_match","text":"string match regular expression?","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does a string match a regular expression? — expect_match","text":"","code":"expect_match( object, regexp, perl = FALSE, fixed = FALSE, ..., all = TRUE, info = NULL, label = NULL ) expect_no_match( object, regexp, perl = FALSE, fixed = FALSE, ..., all = TRUE, info = NULL, label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does a string match a regular expression? — expect_match","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. regexp Regular expression test . perl logical. Perl-compatible regexps used? fixed TRUE, treats regexp string matched exactly (regular expressions). Overrides perl. ... Arguments passed base::grepl ignore.case FALSE, pattern matching case sensitive TRUE, case ignored matching. useBytes logical. TRUE matching done byte--byte rather character--character. See ‘Details’. elements actual value match regexp (TRUE), one need match (FALSE). info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Does a string match a regular expression? — expect_match","text":"expect_match() wrapper around grepl(). See documentation detail individual arguments. expect_no_match() provides complementary case, checking string match regular expression.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Does a string match a regular expression? — expect_match","text":"expect_no_match(): Check string match regular expression.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_match.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does a string match a regular expression? — expect_match","text":"","code":"expect_match(\"Testing is fun\", \"fun\") expect_match(\"Testing is fun\", \"f.n\") expect_no_match(\"Testing is fun\", \"horrible\") if (FALSE) { expect_match(\"Testing is fun\", \"horrible\") # Zero-length inputs always fail expect_match(character(), \".\") }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector with (given) names? — expect_named","title":"Does code return a vector with (given) names? — expect_named","text":"can either check presence names (leaving expected blank), specific names (supplying vector names), absence names (NULL).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector with (given) names? — expect_named","text":"","code":"expect_named( object, expected, ignore.order = FALSE, ignore.case = FALSE, info = NULL, label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector with (given) names? — expect_named","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. expected Character vector expected names. Leave missing match names. Use NULL check absence names. ignore.order TRUE, sorts names comparing ignore effect order. ignore.case TRUE, lowercases names ignore effect case. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_named.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector with (given) names? — expect_named","text":"","code":"x <- c(a = 1, b = 2, c = 3) expect_named(x) expect_named(x, c(\"a\", \"b\", \"c\")) # Use options to control sensitivity expect_named(x, c(\"B\", \"C\", \"A\"), ignore.order = TRUE, ignore.case = TRUE) # Can also check for the absence of names with NULL z <- 1:4 expect_named(z, NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code run without error, warning, message, or other condition? — expect_no_error","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"expectations opposite expect_error(), expect_warning(), expect_message(), expect_condition(). assert absence error, warning, message, respectively.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"","code":"expect_no_error(object, ..., message = NULL, class = NULL) expect_no_warning(object, ..., message = NULL, class = NULL) expect_no_message(object, ..., message = NULL, class = NULL) expect_no_condition(object, ..., message = NULL, class = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ... dots future extensions must empty. message, class default, message = NULL, class = NULL, fail error/warning/message/condition. many cases, particularly testing warnings messages, want specific condition hoping see, .e. condition motivated write test. Similar expect_error() friends, can specify message (regular expression message condition must match) /class (class condition must inherit ). ensures message/warnings want never recur, allowing new messages/warnings bubble deal . Note use message errors/warnings/messages generate, base R generates (tend stable). Avoid tests rely specific text generated another package since can easily change. need test text generated another package, either protect test skip_on_cran() use expect_snapshot().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_no_error.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code run without error, warning, message, or other condition? — expect_no_error","text":"","code":"expect_no_warning(1 + 1) foo <- function(x) { warning(\"This is a problem!\") } # warning doesn't match so bubbles up: expect_no_warning(foo(), message = \"bananas\") #> Warning: This is a problem! # warning does match so causes a failure: try(expect_no_warning(foo(), message = \"problem\")) #> Error : Expected `foo()` to run without any warnings matching pattern 'problem'. #> ℹ Actually got a with text: #> This is a problem!"},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return NULL? — expect_null","title":"Does code return NULL? — expect_null","text":"special case NULL singleton possible check either expect_equal(x, NULL) expect_type(x, \"NULL\").","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return NULL? — expect_null","text":"","code":"expect_null(object, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return NULL? — expect_null","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_null.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return NULL? — expect_null","text":"","code":"x <- NULL y <- 10 expect_null(x) show_failure(expect_null(y)) #> Failed expectation: #> `y` is not NULL #> #> `actual` is a double vector (10) #> `expected` is NULL"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code print output to the console? — expect_output","title":"Does code print output to the console? — expect_output","text":"Test output produced print() cat(). best used simple output; complex cases use expect_snapshot().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code print output to the console? — expect_output","text":"","code":"expect_output( object, regexp = NULL, ..., info = NULL, label = NULL, width = 80 )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code print output to the console? — expect_output","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. regexp Regular expression test . character vector giving regular expression must match output. NULL, default, asserts output, check specific value. NA, asserts output. ... Arguments passed expect_match elements actual value match regexp (TRUE), one need match (FALSE). fixed TRUE, treats regexp string matched exactly (regular expressions). Overrides perl. perl logical. Perl-compatible regexps used? info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use . width Number characters per line output. inherit getOption(\"width\") tests always use output width, minimising spurious differences.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code print output to the console? — expect_output","text":"first argument, invisibly.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_output.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code print output to the console? — expect_output","text":"","code":"str(mtcars) #> 'data.frame':\t32 obs. of 11 variables: #> $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... #> $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... #> $ disp: num 160 160 108 258 360 ... #> $ hp : num 110 110 93 110 175 105 245 62 95 123 ... #> $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... #> $ wt : num 2.62 2.88 2.32 3.21 3.44 ... #> $ qsec: num 16.5 17 18.6 19.4 17 ... #> $ vs : num 0 0 1 1 0 1 0 1 1 1 ... #> $ am : num 1 1 1 0 0 0 0 0 0 0 ... #> $ gear: num 4 4 4 3 3 3 3 4 4 4 ... #> $ carb: num 4 4 1 1 2 1 4 2 2 4 ... expect_output(str(mtcars), \"32 obs\") expect_output(str(mtcars), \"11 variables\") # You can use the arguments of grepl to control the matching expect_output(str(mtcars), \"11 VARIABLES\", ignore.case = TRUE) expect_output(str(mtcars), \"$ mpg\", fixed = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Expectations: is the output or the value equal to a known good value? — expect_output_file","title":"Expectations: is the output or the value equal to a known good value? — expect_output_file","text":"expect_output_file() behaves identically expect_known_output().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_output_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Expectations: is the output or the value equal to a known good value? — expect_output_file","text":"","code":"expect_output_file( object, file, update = TRUE, ..., info = NULL, label = NULL, print = FALSE, width = 80 )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_output_file.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Expectations: is the output or the value equal to a known good value? — expect_output_file","text":"expect_output_file() deprecated 3rd edition; please use expect_snapshot_output() friends instead.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a reference to the expected object? — expect_reference","title":"Does code return a reference to the expected object? — expect_reference","text":"expect_reference() compares underlying memory addresses two symbols. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a reference to the expected object? — expect_reference","text":"","code":"expect_reference( object, expected, info = NULL, label = NULL, expected.label = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a reference to the expected object? — expect_reference","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label, expected.label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_reference.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Does code return a reference to the expected object? — expect_reference","text":"expect_reference() deprecated third edition. know , really need behaviour, just use is_reference() directly: expect_true(rlang::is_reference(x, y)).","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector containing the expected values? — expect_setequal","title":"Does code return a vector containing the expected values? — expect_setequal","text":"expect_setequal(x, y) tests every element x occurs y, every element y occurs x. expect_contains(x, y) tests x contains every element y (.e. y subset x). expect_in(x, y) tests every element x y (.e. x subset y). expect_mapequal(x, y) tests x y names, x[names(y)] equals y.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector containing the expected values? — expect_setequal","text":"","code":"expect_setequal(object, expected) expect_mapequal(object, expected) expect_contains(object, expected) expect_in(object, expected)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector containing the expected values? — expect_setequal","text":"object, expected Computation value compare . arguments supports limited unquoting make easier generate readable failures within function loop. See quasi_label details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Does code return a vector containing the expected values? — expect_setequal","text":"Note expect_setequal() ignores names, warned object expected .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_setequal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector containing the expected values? — expect_setequal","text":"","code":"expect_setequal(letters, rev(letters)) show_failure(expect_setequal(letters[-1], rev(letters))) #> Failed expectation: #> letters[-1] (`actual`) and rev(letters) (`expected`) don't have the same values. #> * Only in `actual`: \"a\" #> x <- list(b = 2, a = 1) expect_mapequal(x, list(a = 1, b = 2)) show_failure(expect_mapequal(x, list(a = 1))) #> Failed expectation: #> Names absent from `expected`: \"b\", show_failure(expect_mapequal(x, list(a = 1, b = \"x\"))) #> Failed expectation: #> act$val[exp_nms] (`actual`) not equal to exp$val (`expected`). #> #> `actual$b` is a double vector (2) #> `expected$b` is a character vector ('x') show_failure(expect_mapequal(x, list(a = 1, b = 2, c = 3))) #> Failed expectation: #> Names absent from `object`: \"c\","},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code execute silently? — expect_silent","title":"Does code execute silently? — expect_silent","text":"Checks code produces output, messages, warnings.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code execute silently? — expect_silent","text":"","code":"expect_silent(object)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code execute silently? — expect_silent","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Does code execute silently? — expect_silent","text":"first argument, invisibly.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_silent.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code execute silently? — expect_silent","text":"","code":"expect_silent(\"123\") f <- function() { message(\"Hi!\") warning(\"Hey!!\") print(\"OY!!!\") } if (FALSE) { expect_silent(f()) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot testing — expect_snapshot","title":"Snapshot testing — expect_snapshot","text":"Snapshot tests (aka golden tests) similar unit tests except expected result stored separate file managed testthat. Snapshot tests useful expected value large, intent code something can verified human (e.g. useful error message). Learn vignette(\"snapshotting\"). expect_snapshot() runs code executed console, records results, including output, messages, warnings, errors. just want compare result, try expect_snapshot_value().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot testing — expect_snapshot","text":"","code":"expect_snapshot( x, cran = FALSE, error = FALSE, transform = NULL, variant = NULL, cnd_class = FALSE )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot testing — expect_snapshot","text":"x Code evaluate. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. error expect code throw error? expectation fail (even CRAN) unexpected error thrown expected error thrown. transform Optionally, function scrub sensitive stochastic text output. take character vector lines input return modified character vector output. variant non-NULL, results saved _snaps/{variant}/{test.md}, variant must single string suitable use directory name. can use variants deal cases snapshot output varies want capture test variations. Common use cases include variations operating system, R version, version key dependency. Variants advanced feature. use , need carefully think testing strategy ensure important variants covered automated tests, ensure way get snapshot changes CI system back repo. cnd_class Whether include class messages, warnings, errors snapshot. specific class included, .e. first element class(cnd).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot.html","id":"workflow","dir":"Reference","previous_headings":"","what":"Workflow","title":"Snapshot testing — expect_snapshot","text":"first time run snapshot expectation run x, capture results, record tests/testthat/_snaps/{test}.md. test file gets snapshot file, e.g. test-foo.R get _snaps/foo.md. important review Markdown files commit git. designed human readable, always review new additions ensure salient information captured. also carefully reviewed pull requests, make sure snapshots updated expected way. subsequent runs, result x compared value stored disk. different, expectation fail, new file _snaps/{test}.new.md created. change deliberate, can approve change snapshot_accept() tests pass next time run . Note snapshotting can work executing complete test file (test_file(), test_dir(), friends) otherwise way figure snapshot path. run snapshot tests interactively, just display current value.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot testing for whole files — expect_snapshot_file","title":"Snapshot testing for whole files — expect_snapshot_file","text":"Whole file snapshot testing designed testing objects convenient textual representation, initial support images (.png, .jpg, .svg), data frames (.csv), text files (.R, .txt, .json, ...). first time expect_snapshot_file() run, create _snaps/{test}/{name}.{ext} containing reference output. Future runs compared reference: different, test fail new results saved _snaps/{test}/{name}.new.{ext}. review failures, call snapshot_review(). generally expect function used via wrapper takes care ensuring output reproducible possible, e.g. automatically skipping tests known images reproduced exactly.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot testing for whole files — expect_snapshot_file","text":"","code":"expect_snapshot_file( path, name = basename(path), binary = lifecycle::deprecated(), cran = FALSE, compare = NULL, transform = NULL, variant = NULL ) announce_snapshot_file(path, name = basename(path)) compare_file_binary(old, new) compare_file_text(old, new)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot testing for whole files — expect_snapshot_file","text":"path Path file snapshot. Optional announce_snapshot_file() name supplied. name Snapshot name, taken path default. binary Please use compare argument instead. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. compare function used compare snapshot files. take two inputs, paths old new snapshot, return either TRUE FALSE. defaults compare_file_text name extension .r, .R, .Rmd, .md, .txt, otherwise uses compare_file_binary. compare_file_binary() compares byte--byte compare_file_text() compares lines--line, ignoring difference Windows Mac/Linux line endings. transform Optionally, function scrub sensitive stochastic text output. take character vector lines input return modified character vector output. variant -NULL, results saved _snaps/{variant}/{test}/{name}.{ext}. allows create different snapshots different scenarios, like different operating systems different R versions. old, new Paths old new snapshot files.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"announcing-snapshots","dir":"Reference","previous_headings":"","what":"Announcing snapshots","title":"Snapshot testing for whole files — expect_snapshot_file","text":"testthat automatically detects dangling snapshots written _snaps directory longer corresponding R code generate . dangling files automatically deleted clutter snapshot directory. However want preserve snapshot files R code executed unexpected error skip(). Let testthat know files calling announce_snapshot_file() expect_snapshot_file().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_file.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Snapshot testing for whole files — expect_snapshot_file","text":"","code":"# To use expect_snapshot_file() you'll typically need to start by writing # a helper function that creates a file from your code, returning a path save_png <- function(code, width = 400, height = 400) { path <- tempfile(fileext = \".png\") png(path, width = width, height = height) on.exit(dev.off()) code path } path <- save_png(plot(1:5)) path #> [1] \"/tmp/RtmpmdYlvE/file1939d968908.png\" if (FALSE) { expect_snapshot_file(save_png(hist(mtcars$mpg)), \"plot.png\") } # You'd then also provide a helper that skips tests where you can't # be sure of producing exactly the same output expect_snapshot_plot <- function(name, code) { # Other packages might affect results skip_if_not_installed(\"ggplot2\", \"2.0.0\") # Or maybe the output is different on some operation systems skip_on_os(\"windows\") # You'll need to carefully think about and experiment with these skips name <- paste0(name, \".png\") # Announce the file before touching `code`. This way, if `code` # unexpectedly fails or skips, testthat will not auto-delete the # corresponding snapshot file. announce_snapshot_file(name = name) path <- save_png(code) expect_snapshot_file(path, name) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot helpers — expect_snapshot_output","title":"Snapshot helpers — expect_snapshot_output","text":"snapshotting functions questioning developed expect_snapshot() sure still role play. expect_snapshot_output() captures just output printed console. expect_snapshot_error() captures error message optionally checks class. expect_snapshot_warning() captures warning message optionally checks class.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot helpers — expect_snapshot_output","text":"","code":"expect_snapshot_output(x, cran = FALSE, variant = NULL) expect_snapshot_error(x, class = \"error\", cran = FALSE, variant = NULL) expect_snapshot_warning(x, class = \"warning\", cran = FALSE, variant = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot helpers — expect_snapshot_output","text":"x Code evaluate. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. variant non-NULL, results saved _snaps/{variant}/{test.md}, variant must single string suitable use directory name. can use variants deal cases snapshot output varies want capture test variations. Common use cases include variations operating system, R version, version key dependency. Variants advanced feature. use , need carefully think testing strategy ensure important variants covered automated tests, ensure way get snapshot changes CI system back repo. class Class expected error warning. expectation always fail (even CRAN) error class seen executing x.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_value.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot testing for values — expect_snapshot_value","title":"Snapshot testing for values — expect_snapshot_value","text":"Captures result function, flexibly serializing text representation stored snapshot file. See expect_snapshot() details snapshot testing.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_value.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot testing for values — expect_snapshot_value","text":"","code":"expect_snapshot_value( x, style = c(\"json\", \"json2\", \"deparse\", \"serialize\"), cran = FALSE, tolerance = testthat_tolerance(), ..., variant = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/expect_snapshot_value.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot testing for values — expect_snapshot_value","text":"x Code evaluate. style Serialization style use: json uses jsonlite::fromJSON() jsonlite::toJSON(). produces simplest output works relatively simple objects. json2 uses jsonlite::serializeJSON() jsonlite::unserializeJSON() verbose work wider range type. deparse uses deparse(), generates depiction object using R code. serialize() produces binary serialization object using serialize(). guaranteed work R object, produces completely opaque serialization. cran expectations verified CRAN? default, , snapshot tests tend fragile often rely minor details dependencies. tolerance Numerical tolerance: differences (sense base::.equal()) smaller value ignored. default tolerance sqrt(.Machine$double.eps), unless long doubles available, case test skipped. ... Passed waldo::compare() can control details comparison. variant non-NULL, results saved _snaps/{variant}/{test.md}, variant must single string suitable use directory name. can use variants deal cases snapshot output varies want capture test variations. Common use cases include variations operating system, R version, version key dependency. Variants advanced feature. use , need carefully think testing strategy ensure important variants covered automated tests, ensure way get snapshot changes CI system back repo.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_success.html","id":null,"dir":"Reference","previous_headings":"","what":"Tools for testing expectations — expect_success","title":"Tools for testing expectations — expect_success","text":"Use expectations test expectations. Use show_failure() examples print failure message without throwing error.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_success.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tools for testing expectations — expect_success","text":"","code":"expect_success(expr) expect_failure(expr, message = NULL, ...) show_failure(expr)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_success.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tools for testing expectations — expect_success","text":"expr Expression evaluates single expectation. message Check failure message matches regexp. ... arguments passed expect_match().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":null,"dir":"Reference","previous_headings":"","what":"Expect that a condition holds. — expect_that","title":"Expect that a condition holds. — expect_that","text":"old style testing longer encouraged.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Expect that a condition holds. — expect_that","text":"","code":"expect_that(object, condition, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Expect that a condition holds. — expect_that","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. condition, function returns whether condition met, , error message display. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Expect that a condition holds. — expect_that","text":"(internal) expectation result invisible list","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Expect that a condition holds. — expect_that","text":"style testing formally deprecated 3rd edition. Use specific expect_ function instead.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/expect_that.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Expect that a condition holds. — expect_that","text":"","code":"expect_that(5 * 2, equals(10)) #> Warning: `expect_that()` was deprecated in the 3rd edition. expect_that(sqrt(2) ^ 2, equals(2)) #> Warning: `expect_that()` was deprecated in the 3rd edition. if (FALSE) { expect_that(sqrt(2) ^ 2, is_identical_to(2)) }"},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return a vector with the expected size and/or prototype? — expect_vector","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"expect_vector() thin wrapper around vctrs::vec_assert(), converting results function expectations used testthat. means used vctrs ptype (prototype) size. See details https://vctrs.r-lib.org/articles/type-size.html","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"","code":"expect_vector(object, ptype = NULL, size = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. ptype (Optional) Vector prototype test . size-0 (empty) generalised vector. size (Optional) Size check .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expect_vector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return a vector with the expected size and/or prototype? — expect_vector","text":"","code":"if (requireNamespace(\"vctrs\") && packageVersion(\"vctrs\") > \"0.1.0.9002\") { expect_vector(1:10, ptype = integer(), size = 10) show_failure(expect_vector(1:10, ptype = integer(), size = 5)) show_failure(expect_vector(1:10, ptype = character(), size = 5)) } #> Failed expectation: #> `1:10` must have size 5, not size 10. #> Failed expectation: #> `1:10` must be a vector with type . #> Instead, it has type ."},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct an expectation object — expectation","title":"Construct an expectation object — expectation","text":"advanced use . creating expectation, call expect() instead. See vignette(\"custom-expectation\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct an expectation object — expectation","text":"","code":"expectation(type, message, srcref = NULL, trace = NULL) new_expectation( type, message, ..., srcref = NULL, trace = NULL, .subclass = NULL ) exp_signal(exp) is.expectation(x)"},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct an expectation object — expectation","text":"type Expectation type. Must one \"success\", \"failure\", \"error\", \"skip\", \"warning\". message Message describing test failure srcref Optional srcref giving location test. trace optional backtrace created rlang::trace_back(). supplied, expectation displayed backtrace. ... Additional attributes expectation object. .subclass optional subclass expectation object. exp expectation object, created new_expectation(). x object test class membership","code":""},{"path":"https://testthat.r-lib.org/dev/reference/expectation.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Construct an expectation object — expectation","text":"Create expectation expectation() new_expectation() signal exp_signal().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":null,"dir":"Reference","previous_headings":"","what":"Default expectations that always succeed or fail. — fail","title":"Default expectations that always succeed or fail. — fail","text":"allow manually trigger success failure. Failure particularly useful pre-condition mark test yet implemented.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default expectations that always succeed or fail. — fail","text":"","code":"fail( message = \"Failure has been forced\", info = NULL, trace_env = caller_env() ) succeed(message = \"Success has been forced\", info = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default expectations that always succeed or fail. — fail","text":"message string display. info Character vector continuing additional information. Included backward compatibility new expectations use . trace_env .null(trace), used automatically generate traceback running test_code()/test_file() trace_env. generally need set wrapping expectation inside another function.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/fail.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Default expectations that always succeed or fail. — fail","text":"","code":"if (FALSE) { test_that(\"this test fails\", fail()) test_that(\"this test succeeds\", succeed()) }"},{"path":"https://testthat.r-lib.org/dev/reference/find_reporter.html","id":null,"dir":"Reference","previous_headings":"","what":"Find reporter object given name or object. — find_reporter","title":"Find reporter object given name or object. — find_reporter","text":"found, return informative error message. Pass character vector create MultiReporter composed individual reporters. return null given NULL.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_reporter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Find reporter object given name or object. — find_reporter","text":"","code":"find_reporter(reporter)"},{"path":"https://testthat.r-lib.org/dev/reference/find_reporter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Find reporter object given name or object. — find_reporter","text":"reporter name reporter(s), reporter object(s)","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":null,"dir":"Reference","previous_headings":"","what":"Find test files — find_test_scripts","title":"Find test files — find_test_scripts","text":"Find test files","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Find test files — find_test_scripts","text":"","code":"find_test_scripts( path, filter = NULL, invert = FALSE, ..., full.names = TRUE, start_first = NULL )"},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Find test files — find_test_scripts","text":"path path tests filter NULL, tests file names matching regular expression executed. Matching performed file name stripped \"test-\" \".R\". invert TRUE return files match. ... Additional arguments passed grepl() control filtering. start_first character vector file patterns (globs, see utils::glob2rx()). patterns file names (base names), whole paths. testthat starts files matching first pattern first, ones matching second, etc. rest files, alphabetically. Parallel tests tend finish quicker start slowest files first. NULL means alphabetical order.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/find_test_scripts.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Find test files — find_test_scripts","text":"character vector paths","code":""},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"See https://adv-r.hadley.nz/oo.html overview R's OO systems, vocabulary used . expect_type(x, type) checks typeof(x) type. expect_s3_class(x, class) checks x S3 object inherits() class expect_s3_class(x, NA) checks x S3 object. expect_s4_class(x, class) checks x S4 object () class. expect_s4_class(x, NA) checks x S4 object. See expect_vector() testing properties objects created vctrs.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"","code":"expect_type(object, type) expect_s3_class(object, class, exact = FALSE) expect_s4_class(object, class)"},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. type String giving base type (returned typeof()). class Either character vector class names, expect_s3_class() expect_s4_class(), NA assert object S3 S4 object. exact FALSE, default, checks object inherits class. TRUE, checks object class identical class.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/inheritance-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return an object inheriting from the expected base type, S3 class,\nor S4 class? — inheritance-expectations","text":"","code":"x <- data.frame(x = 1:10, y = \"x\", stringsAsFactors = TRUE) # A data frame is an S3 object with class data.frame expect_s3_class(x, \"data.frame\") show_failure(expect_s4_class(x, \"data.frame\")) #> Failed expectation: #> `x` is not an S4 object # A data frame is built from a list: expect_type(x, \"list\") # An integer vector is an atomic vector of type \"integer\" expect_type(x$x, \"integer\") # It is not an S3 object show_failure(expect_s3_class(x$x, \"integer\")) #> Failed expectation: #> x$x is not an S3 object # Above, we requested data.frame() converts strings to factors: show_failure(expect_type(x$y, \"character\")) #> Failed expectation: #> x$y has type 'integer', not 'character'. expect_s3_class(x$y, \"factor\") expect_type(x$y, \"integer\")"},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":null,"dir":"Reference","previous_headings":"","what":"Is an error informative? — is_informative_error","title":"Is an error informative? — is_informative_error","text":"is_informative_error() generic predicate indicates whether testthat users explicitly test error class. Since longer recommend , generic deprecated.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Is an error informative? — is_informative_error","text":"","code":"is_informative_error(x, ...)"},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Is an error informative? — is_informative_error","text":"x error object. ... dots future extensions must empty.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_informative_error.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Is an error informative? — is_informative_error","text":"classes hard-coded uninformative: simpleError rlang_error unless subclass detected Rcpp::eval_error Rcpp::exception","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_testing.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine testing status — is_testing","title":"Determine testing status — is_testing","text":"functions help determine code running particular testing context: is_testing() TRUE inside test. is_snapshot() TRUE inside snapshot test is_checking() TRUE inside R CMD check (.e. test_check()). is_parallel() TRUE tests run parallel. testing_package() gives name package tested. common use functions compute default value quiet argument is_testing() && !is_snapshot(). case, want avoid run-time dependency testthat, case just copy implementation functions utils.R similar.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/is_testing.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine testing status — is_testing","text":"","code":"is_testing() is_parallel() is_checking() is_snapshot() testing_package()"},{"path":"https://testthat.r-lib.org/dev/reference/local_edition.html","id":null,"dir":"Reference","previous_headings":"","what":"Temporarily change the active testthat edition — local_edition","title":"Temporarily change the active testthat edition — local_edition","text":"local_edition() allows temporarily (within single test single test file) change active edition testthat. edition_get() allows retrieve currently active edition.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_edition.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Temporarily change the active testthat edition — local_edition","text":"","code":"local_edition(x, .env = parent.frame()) edition_get()"},{"path":"https://testthat.r-lib.org/dev/reference/local_edition.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Temporarily change the active testthat edition — local_edition","text":"x Edition single integer. .env Environment controls scope changes. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":null,"dir":"Reference","previous_headings":"","what":"Mocking tools — local_mocked_bindings","title":"Mocking tools — local_mocked_bindings","text":"with_mocked_bindings() local_mocked_bindings() provide tools \"mocking\", temporarily redefining function behaves differently tests. helpful testing functions depend external state (.e. reading value file website, pretending package installed). functions represent second attempt bringing mocking testthat, incorporating learned mockr, mockery, mockthat packages.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Mocking tools — local_mocked_bindings","text":"","code":"local_mocked_bindings(..., .package = NULL, .env = caller_env()) with_mocked_bindings(code, ..., .package = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Mocking tools — local_mocked_bindings","text":"... Name-value pairs providing functions mock. .package name package mocked functions inserted. Generally, supply automatically detected whole package tests run one package active development (.e. loaded pkgload::load_all()). recommend using mock functions packages, modify namespaces . .env Environment defines effect scope. expert use . code Code execute specified bindings.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"use","dir":"Reference","previous_headings":"","what":"Use","title":"Mocking tools — local_mocked_bindings","text":"four places function trying mock might come : Internal package. Imported external package via NAMESPACE. base environment. Called external package ::. described turn .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"internal-amp-imported-functions","dir":"Reference","previous_headings":"","what":"Internal & imported functions","title":"Mocking tools — local_mocked_bindings","text":"mock internal imported functions way. example, take code: matter whether another_function() defined package imported dependency @import @importFrom, mock way:","code":"some_function <- function() { another_function() } local_mocked_bindings( another_function = function(...) \"new_value\" )"},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"base-functions","dir":"Reference","previous_headings":"","what":"Base functions","title":"Mocking tools — local_mocked_bindings","text":"mock function base package, need make sure binding function package. easiest binding value NULL. example, wanted mock interactive() package, need include code somewhere package: necessary? with_mocked_bindings() local_mocked_bindings() work temporarily modifying bindings within package's namespace. tests running inside R CMD check namespace locked means possible create new bindings need make sure binding exists already.","code":"interactive <- NULL"},{"path":"https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html","id":"namespaced-calls","dir":"Reference","previous_headings":"","what":"Namespaced calls","title":"Mocking tools — local_mocked_bindings","text":"trickier mock functions packages call ::. example, take minor variation: mock function, need modify another_function() inside anotherpackage package. can supplying .package argument local_mocked_bindings() recommend affect calls anotherpackage::another_function(), just calls originating package. Instead, safer either import function package, make wrapper can mock:","code":"some_function <- function() { anotherpackage::another_function() } some_function <- function() { my_wrapper() } my_wrapper <- function(...) { anotherpackage::another_function(...) } local_mocked_bindings( my_wrapper = function(...) \"new_value\" )"},{"path":"https://testthat.r-lib.org/dev/reference/local_snapshotter.html","id":null,"dir":"Reference","previous_headings":"","what":"Instantiate local snapshotting context — local_snapshotter","title":"Instantiate local snapshotting context — local_snapshotter","text":"Needed want run snapshot tests outside usual testthat framework expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_snapshotter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Instantiate local snapshotting context — local_snapshotter","text":"","code":"local_snapshotter( snap_dir = NULL, cleanup = FALSE, fail_on_new = FALSE, .env = parent.frame() )"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":null,"dir":"Reference","previous_headings":"","what":"Locally set options for maximal test reproducibility — local_test_context","title":"Locally set options for maximal test reproducibility — local_test_context","text":"local_test_context() run automatically test_that() may want run want replicate test results interactively. run inside function, effects automatically reversed function exits; running global environment, use withr::deferred_run() undo. local_reproducible_output() run automatically test_that() 3rd edition. might want call override default settings inside test, want test Unicode, coloured output, non-standard width.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Locally set options for maximal test reproducibility — local_test_context","text":"","code":"local_test_context(.env = parent.frame()) local_reproducible_output( width = 80, crayon = FALSE, unicode = FALSE, rstudio = FALSE, hyperlinks = FALSE, lang = \"en\", .env = parent.frame() )"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Locally set options for maximal test reproducibility — local_test_context","text":".env Environment use scoping; expert use . width Value \"width\" option. crayon Determines whether crayon (now cli) colour applied. unicode Value \"cli.unicode\" option. test skipped l10n_info()$`UTF-8` FALSE. rstudio pretend inside RStudio? hyperlinks use ANSI hyperlinks. lang Optionally, supply BCP47 language code set language used translating error messages. lower case two letter ISO 639 country code, optionally followed \"_\" \"-\" upper case two letter ISO 3166 region code.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Locally set options for maximal test reproducibility — local_test_context","text":"local_test_context() sets TESTTHAT = \"true\", ensures is_testing() returns TRUE allows code tell run testthat. third edition, local_test_context() also calls local_reproducible_output() temporary sets following options: cli.dynamic = FALSE tests assume run dynamic console (.e. one can move cursor around). cli.unicode (default: FALSE) cli package never generates unicode output (normally cli uses unicode Linux/Mac Windows). Windows easily save unicode output disk, must set false consistency. cli.condition_width = Inf new lines introduced width-wrapping condition messages interfere message matching. crayon.enabled (default: FALSE) suppresses ANSI colours generated cli crayon packages (normally colours used cli detects terminal supports colour). cli.num_colors (default: 1L) crayon option. lifecycle_verbosity = \"warning\" every lifecycle problem always generates warning (otherwise deprecated functions generate warning every time). max.print = 99999 number values printed. OutDec = \".\" numbers always uses . decimal point (European users sometimes set OutDec = \",\"). rlang_interactive = FALSE rlang::is_interactive() returns FALSE, code uses pretends non-interactive environment. useFancyQuotes = FALSE base R functions always use regular (straight) quotes (otherwise default locale dependent, see sQuote() details). width (default: 80) control width printed output (usually varies size console). modifies following env vars: Unsets RSTUDIO, ensures RStudio never detected running. Sets LANGUAGE = \"en\", ensures message translation occurs. Finally, sets collation locale \"C\", ensures character sorting regardless system locale.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_context.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Locally set options for maximal test reproducibility — local_test_context","text":"","code":"local({ local_test_context() cat(cli::col_blue(\"Text will not be colored\")) cat(cli::symbol$ellipsis) cat(\"\\n\") }) #> Text will not be colored... test_that(\"test ellipsis\", { local_reproducible_output(unicode = FALSE) expect_equal(cli::symbol$ellipsis, \"...\") local_reproducible_output(unicode = TRUE) expect_equal(cli::symbol$ellipsis, \"\\u2026\") }) #> Test passed"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_directory.html","id":null,"dir":"Reference","previous_headings":"","what":"Locally set test directory options — local_test_directory","title":"Locally set test directory options — local_test_directory","text":"expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/local_test_directory.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Locally set test directory options — local_test_directory","text":"","code":"local_test_directory(path, package = NULL, .env = parent.frame())"},{"path":"https://testthat.r-lib.org/dev/reference/local_test_directory.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Locally set test directory options — local_test_directory","text":"path Path directory files package Optional package name, known.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code return TRUE or FALSE? — logical-expectations","title":"Does code return TRUE or FALSE? — logical-expectations","text":"fall-back expectations can use none specific expectations apply. disadvantage may get less informative error message.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code return TRUE or FALSE? — logical-expectations","text":"","code":"expect_true(object, info = NULL, label = NULL) expect_false(object, info = NULL, label = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code return TRUE or FALSE? — logical-expectations","text":"object Object test. Supports limited unquoting make easier generate readable failures within function loop. See quasi_label details. info Extra information included message. argument soft-deprecated used new code. Instead see alternatives quasi_label. label Used customise failure messages. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Does code return TRUE or FALSE? — logical-expectations","text":"Attributes ignored.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/logical-expectations.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Does code return TRUE or FALSE? — logical-expectations","text":"","code":"expect_true(2 == 2) # Failed expectations will throw an error if (FALSE) { expect_true(2 != 2) } expect_true(!(2 != 2)) # or better: expect_false(2 != 2) a <- 1:3 expect_true(length(a) == 3) # but better to use more specific expectation, if available expect_equal(length(a), 3)"},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":null,"dir":"Reference","previous_headings":"","what":"Make an equality test. — make_expectation","title":"Make an equality test. — make_expectation","text":"convenience function make expectation checks input stays .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make an equality test. — make_expectation","text":"","code":"make_expectation(x, expectation = \"equals\")"},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make an equality test. — make_expectation","text":"x vector values expectation type equality want test (\"equals\", \"is_equivalent_to\", \"is_identical_to\")","code":""},{"path":"https://testthat.r-lib.org/dev/reference/make_expectation.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make an equality test. — make_expectation","text":"","code":"x <- 1:10 make_expectation(x) #> expect_equal(x, 1:10) make_expectation(mtcars$mpg) #> expect_equal(mtcars$mpg, c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, #> 24.4, 22.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, #> 30.4, 33.9, 21.5, 15.5, 15.2, 13.3, 19.2, 27.3, 26, 30.4, 15.8, #> 19.7, 15, 21.4)) df <- data.frame(x = 2) make_expectation(df) #> expect_equal(df, structure(list(x = 2), class = \"data.frame\", row.names = c(NA, #> -1L)))"},{"path":"https://testthat.r-lib.org/dev/reference/not.html","id":null,"dir":"Reference","previous_headings":"","what":"Negate an expectation — not","title":"Negate an expectation — not","text":"negates expectation, making possible express want opposite standard expectation. function deprecated removed future version.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/not.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Negate an expectation — not","text":"","code":"not(f)"},{"path":"https://testthat.r-lib.org/dev/reference/not.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Negate an expectation — not","text":"f existing expectation function","code":""},{"path":"https://testthat.r-lib.org/dev/reference/oldskool.html","id":null,"dir":"Reference","previous_headings":"","what":"Old-style expectations. — oldskool","title":"Old-style expectations. — oldskool","text":"Initial testthat used style testing looked like expect_that(, equals(b))) allowed expectations read like English sentences, verbose bit cutesy. style continue work soft-deprecated - longer documented, new expectations use new style expect_equal(, b).","code":""},{"path":"https://testthat.r-lib.org/dev/reference/oldskool.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Old-style expectations. — oldskool","text":"","code":"is_null() is_a(class) is_true() is_false() has_names(expected, ignore.order = FALSE, ignore.case = FALSE) is_less_than(expected, label = NULL, ...) is_more_than(expected, label = NULL, ...) equals(expected, label = NULL, ...) is_equivalent_to(expected, label = NULL) is_identical_to(expected, label = NULL) equals_reference(file, label = NULL, ...) shows_message(regexp = NULL, all = FALSE, ...) gives_warning(regexp = NULL, all = FALSE, ...) prints_text(regexp = NULL, ...) throws_error(regexp = NULL, ...) matches(regexp, all = TRUE, ...)"},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":null,"dir":"Reference","previous_headings":"","what":"Quasi-labelling — quasi_label","title":"Quasi-labelling — quasi_label","text":"first argument every expect_ function can use unquoting construct better labels. makes easy create informative labels expectations used inside function loop. quasi_label() wraps details, returning expression label.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Quasi-labelling — quasi_label","text":"","code":"quasi_label(quo, label = NULL, arg = \"quo\")"},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Quasi-labelling — quasi_label","text":"quo quosure created rlang::enquo(). label optional label override default. provided internal usage. Modern expectations include label parameter. arg Argument name shown error message quo missing.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Quasi-labelling — quasi_label","text":"list containing two elements: val evaluate value quo lab quasiquoted label generated quo","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"limitations","dir":"Reference","previous_headings":"","what":"Limitations","title":"Quasi-labelling — quasi_label","text":"expect_ function use unquoting generate informative labels, can use unquoting purposes. Instead, need perform unquoting outside expectation test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/quasi_label.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Quasi-labelling — quasi_label","text":"","code":"f <- function(i) if (i > 3) i * 9 else i * 10 i <- 10 # This sort of expression commonly occurs inside a for loop or function # And the failure isn't helpful because you can't see the value of i # that caused the problem: show_failure(expect_equal(f(i), i * 10)) #> Failed expectation: #> f(i) (`actual`) not equal to i * 10 (`expected`). #> #> `actual`: 90 #> `expected`: 100 # To overcome this issue, testthat allows you to unquote expressions using # !!. This causes the failure message to show the value rather than the # variable name show_failure(expect_equal(f(!!i), !!(i * 10))) #> Failed expectation: #> f(10) (`actual`) not equal to 100 (`expected`). #> #> `actual`: 90 #> `expected`: 100"},{"path":"https://testthat.r-lib.org/dev/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. magrittr %>%","code":""},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":null,"dir":"Reference","previous_headings":"","what":"Get and set active reporter. — reporter-accessors","title":"Get and set active reporter. — reporter-accessors","text":"get_reporter() set_reporter() access modify current \"active\" reporter. Generally, functions called directly; instead use with_reporter() temporarily change, reset, active reporter.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get and set active reporter. — reporter-accessors","text":"","code":"set_reporter(reporter) get_reporter() with_reporter(reporter, code, start_end_reporter = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get and set active reporter. — reporter-accessors","text":"reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. code Code execute. start_end_reporter reporters start_reporter() end_reporter() methods called? expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/reporter-accessors.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get and set active reporter. — reporter-accessors","text":"with_reporter() invisible returns reporter active code evaluated.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/run_cpp_tests.html","id":null,"dir":"Reference","previous_headings":"","what":"Do C++ tests past? — expect_cpp_tests_pass","title":"Do C++ tests past? — expect_cpp_tests_pass","text":"Test compiled code package package. call function automatically generated tests/testthat/test-cpp.R calling use_catch(); need manually call expectation .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/run_cpp_tests.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Do C++ tests past? — expect_cpp_tests_pass","text":"","code":"expect_cpp_tests_pass(package) run_cpp_tests(package)"},{"path":"https://testthat.r-lib.org/dev/reference/run_cpp_tests.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Do C++ tests past? — expect_cpp_tests_pass","text":"package name package test.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/set_max_fails.html","id":null,"dir":"Reference","previous_headings":"","what":"Set maximum number of test failures allowed before aborting the run — set_max_fails","title":"Set maximum number of test failures allowed before aborting the run — set_max_fails","text":"sets TESTTHAT_MAX_FAILS env var affect current R process processes launched .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/set_max_fails.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Set maximum number of test failures allowed before aborting the run — set_max_fails","text":"","code":"set_max_fails(n)"},{"path":"https://testthat.r-lib.org/dev/reference/set_max_fails.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Set maximum number of test failures allowed before aborting the run — set_max_fails","text":"n Maximum number failures allowed.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/set_state_inspector.html","id":null,"dir":"Reference","previous_headings":"","what":"State inspected — set_state_inspector","title":"State inspected — set_state_inspector","text":"One pernicious challenges debug test runs fine test suite, fails run interactively (similarly, fails randomly running tests parallel). One common causes problem accidentally changing global state previous test (e.g. changing option, environment variable, working directory). hard debug, hard figure test made change. Luckily testthat provides tool figure tests changing global state. can register state inspector set_state_inspector() testthat run test, store results, report differences. example, wanted see tests changing options environment variables, put code tests/testthat/helper-state.R: (might discover packages outside control changing global state, case might want modify function ignore values.) problems can troublesome resolve CRAN check notes report things like connections left open. can easily debug problem :","code":"set_state_inspector(function() { list( options = options(), envvars = Sys.getenv() ) }) set_state_inspector(function() { getAllConnections() })"},{"path":"https://testthat.r-lib.org/dev/reference/set_state_inspector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"State inspected — set_state_inspector","text":"","code":"set_state_inspector(callback)"},{"path":"https://testthat.r-lib.org/dev/reference/set_state_inspector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"State inspected — set_state_inspector","text":"callback Either zero-argument function returns object capturing global state interested , NULL.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":null,"dir":"Reference","previous_headings":"","what":"Skip a test — skip","title":"Skip a test — skip","text":"skip_if() skip_if_not() allow skip tests, immediately concluding test_that() block without executing expectations. allows skip test without failure, reason run (e.g. depends feature specific operating system, requires specific version package). See vignette(\"skipping\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Skip a test — skip","text":"","code":"skip(message = \"Skipping\") 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, arch = NULL) skip_on_ci() skip_on_covr() skip_on_bioc() skip_if_translated(msgid = \"'%s' not found\")"},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Skip a test — skip","text":"message message describing test skipped. condition Boolean condition check. skip_if_not() skip FALSE, skip_if() skip TRUE. pkg Name package check minimum_version Minimum required version package host string hostname lookup os Character vector one operating systems skip . Supported values \"windows\", \"mac\", \"linux\", \"solaris\". arch Character vector one architectures skip . Common values include \"i386\" (32 bit), \"x86_64\" (64 bit), \"aarch64\" (M1 mac). Supplying arch makes test stricter; .e. os arch must match order test skipped. msgid R message identifier used check translation: default uses message included translation packs. See complete list R-base.pot.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"helpers","dir":"Reference","previous_headings":"","what":"Helpers","title":"Skip a test — skip","text":"skip_if_not_installed(\"pkg\") skips tests package \"pkg\" installed loaded (using requireNamespace()). Generally, can assume suggested packages installed, need check specifically, unless particularly difficult install. skip_if_offline() skips internet connection available (using curl::nslookup()) test run CRAN. Requires curl packages installed. skip_if_translated(\"msg\") skips tests \"msg\" translated. skip_on_bioc() skips Bioconductor (using IS_BIOC_BUILD_MACHINE env var). skip_on_cran() skips CRAN (using NOT_CRAN env var set devtools friends). skip_on_covr() skips covr running (using R_COVR env var). skip_on_ci() skips continuous integration systems like GitHub Actions, travis, appveyor (using CI env var). skip_on_os() skips specified operating system(s) (\"windows\", \"mac\", \"linux\", \"solaris\").","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Skip a test — skip","text":"","code":"if (FALSE) skip(\"Some Important Requirement is not available\") 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 }) #> -- Skip: skip example ---------------------------------------------------------- #> Reason: skip #>"},{"path":"https://testthat.r-lib.org/dev/reference/skip_on_travis.html","id":null,"dir":"Reference","previous_headings":"","what":"Superseded skip functions — skip_on_travis","title":"Superseded skip functions — skip_on_travis","text":"skip_on_travis() skip_on_appveyor() superseded skip_on_ci().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/skip_on_travis.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Superseded skip functions — skip_on_travis","text":"","code":"skip_on_travis() skip_on_appveyor()"},{"path":"https://testthat.r-lib.org/dev/reference/snapshot_accept.html","id":null,"dir":"Reference","previous_headings":"","what":"Snapshot management — snapshot_accept","title":"Snapshot management — snapshot_accept","text":"snapshot_accept() accepts modified snapshots. snapshot_review() opens Shiny app shows visual diff modified snapshot. particularly useful whole file snapshots created expect_snapshot_file().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/snapshot_accept.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Snapshot management — snapshot_accept","text":"","code":"snapshot_accept(files = NULL, path = \"tests/testthat\") snapshot_review(files = NULL, path = \"tests/testthat\")"},{"path":"https://testthat.r-lib.org/dev/reference/snapshot_accept.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Snapshot management — snapshot_accept","text":"files Optionally, filter effects snapshots specified files. can snapshot name (e.g. foo foo.md), snapshot file name (e.g. testfile/foo.txt), snapshot file directory (e.g. testfile/). path Path tests.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/source_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Source a file, directory of files, or various important subsets — source_file","title":"Source a file, directory of files, or various important subsets — source_file","text":"used test_dir() friends","code":""},{"path":"https://testthat.r-lib.org/dev/reference/source_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Source a file, directory of files, or various important subsets — source_file","text":"","code":"source_file( path, env = test_env(), chdir = TRUE, desc = NULL, wrap = TRUE, error_call = caller_env() ) source_dir( path, pattern = \"\\\\.[rR]$\", env = test_env(), chdir = TRUE, wrap = TRUE ) source_test_helpers(path = \"tests/testthat\", env = test_env()) source_test_setup(path = \"tests/testthat\", env = test_env()) source_test_teardown(path = \"tests/testthat\", env = test_env())"},{"path":"https://testthat.r-lib.org/dev/reference/source_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Source a file, directory of files, or various important subsets — source_file","text":"path Path files. env Environment evaluate code. chdir Change working directory dirname(path)? desc -NULL, run test description. wrap Automatically wrap code within test_that()? ensures expectations reported, even outside test block. pattern Regular expression used filter files.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/takes_less_than.html","id":null,"dir":"Reference","previous_headings":"","what":"Does code take less than the expected amount of time to run? — takes_less_than","title":"Does code take less than the expected amount of time to run? — takes_less_than","text":"useful performance regression testing.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/takes_less_than.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Does code take less than the expected amount of time to run? — takes_less_than","text":"","code":"takes_less_than(amount)"},{"path":"https://testthat.r-lib.org/dev/reference/takes_less_than.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Does code take less than the expected amount of time to run? — takes_less_than","text":"amount maximum duration seconds","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":null,"dir":"Reference","previous_headings":"","what":"Run code before/after tests — teardown","title":"Run code before/after tests — teardown","text":"longer recommend using setup() teardown(); instead think better practice use test fixture described vignette(\"test-fixtures\"). Code setup() block run immediately clean environment. Code teardown() block run upon completion test file, even exits error. Multiple calls teardown() executed order created.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run code before/after tests — teardown","text":"","code":"teardown(code, env = parent.frame()) setup(code, env = parent.frame())"},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run code before/after tests — teardown","text":"code Code evaluate env Environment code evaluated. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run code before/after tests — teardown","text":"","code":"if (FALSE) { # Old approach tmp <- tempfile() setup(writeLines(\"some test data\", tmp)) teardown(unlink(tmp)) } # Now recommended: local_test_data <- function(env = parent.frame()) { tmp <- tempfile() writeLines(\"some test data\", tmp) withr::defer(unlink(tmp), env) tmp } # Then call local_test_data() in your tests"},{"path":"https://testthat.r-lib.org/dev/reference/teardown_env.html","id":null,"dir":"Reference","previous_headings":"","what":"Run code after all test files — teardown_env","title":"Run code after all test files — teardown_env","text":"environment purpose handle withr::defer(): use want run code tests run. Typically, use withr::defer(cleanup(), teardown_env()) immediately made mess setup-*.R file.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/teardown_env.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run code after all test files — teardown_env","text":"","code":"teardown_env()"},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":null,"dir":"Reference","previous_headings":"","what":"Run all tests in a directory — test_dir","title":"Run all tests in a directory — test_dir","text":"function low-level workhorse powers test_local() test_package(). Generally, call function directly. particular, responsible ensuring functions test available test env (e.g. via load_package). See vignette(\"special-files\") learn conventions test, helper, setup files testthat uses, might use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run all tests in a directory — test_dir","text":"","code":"test_dir( path, filter = NULL, reporter = NULL, env = NULL, ..., load_helpers = TRUE, stop_on_failure = TRUE, stop_on_warning = FALSE, wrap = lifecycle::deprecated(), package = NULL, load_package = c(\"none\", \"installed\", \"source\") )"},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run all tests in a directory — test_dir","text":"path Path directory containing tests. filter NULL, tests file names matching regular expression executed. Matching performed file name stripped \"test-\" \".R\". reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. env Environment execute tests. Expert use . ... Additional arguments passed grepl() control filtering. load_helpers Source helper files running tests? stop_on_failure TRUE, throw error tests fail. stop_on_warning TRUE, throw error tests generate warnings. wrap DEPRECATED package tests belong package, name package. load_package Strategy use load package code: \"none\", default, load package. \"installed\", uses library() load installed package. \"source\", uses pkgload::load_all() source package. configure arguments passed load_all(), add field DESCRIPTION file:","code":"Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run all tests in a directory — test_dir","text":"list (invisibly) containing data test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_dir.html","id":"environments","dir":"Reference","previous_headings":"","what":"Environments","title":"Run all tests in a directory — test_dir","text":"test run clean environment keep tests isolated possible. package tests, environment inherits package's namespace environment, tests can access internal functions objects.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_env.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate default testing environment. — test_env","title":"Generate default testing environment. — test_env","text":"use new environment inherits globalenv() package namespace. ideal world, avoid putting global environment search path tests, currently possible without losing ability load packages tests.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_env.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate default testing environment. — test_env","text":"","code":"test_env(package = NULL)"},{"path":"https://testthat.r-lib.org/dev/reference/test_examples.html","id":null,"dir":"Reference","previous_headings":"","what":"Test package examples — test_examples","title":"Test package examples — test_examples","text":"helper functions make easier test examples package. example counts one test, succeeds code runs without error. Generally, redundant R CMD check, recommended routine practice.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_examples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test package examples — test_examples","text":"","code":"test_examples(path = \"../..\") test_rd(rd, title = attr(rd, \"Rdfile\")) test_example(path, title = path)"},{"path":"https://testthat.r-lib.org/dev/reference/test_examples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test package examples — test_examples","text":"path test_examples(), path directory containing Rd files. test_example(), path single Rd file. Remember working directory tests tests/testthat. rd parsed Rd object, obtained tools::Rd_db() otherwise. title Test title use","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":null,"dir":"Reference","previous_headings":"","what":"Run tests in a single file — test_file","title":"Run tests in a single file — test_file","text":"Helper, setup, teardown files located directory test also run. See vignette(\"special-files\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run tests in a single file — test_file","text":"","code":"test_file( path, reporter = default_compact_reporter(), desc = NULL, package = NULL, ... )"},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run tests in a single file — test_file","text":"path Path file. reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. desc Optionally, supply string run single test (test_that() describe()) description. package tests belong package, name package. ... Additional parameters passed test_dir()","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run tests in a single file — test_file","text":"list (invisibly) containing data test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"environments","dir":"Reference","previous_headings":"","what":"Environments","title":"Run tests in a single file — test_file","text":"test run clean environment keep tests isolated possible. package tests, environment inherits package's namespace environment, tests can access internal functions objects.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_file.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run tests in a single file — test_file","text":"","code":"path <- testthat_example(\"success\") test_file(path) #> #> ══ Testing test-success.R ════════════════════════════════════════════════ #> #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] #> [ FAIL 0 | WARN 0 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 1 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 2 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 3 ] #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] #> #> ── Warning (test-success.R:10:3): some tests have warnings ───────────────────── #> NaNs produced #> Backtrace: #> ▆ #> 1. └─testthat::expect_equal(log(-1), NaN) at test-success.R:10:3 #> 2. └─testthat::quasi_label(enquo(object), label, arg = \"object\") #> 3. └─rlang::eval_bare(expr, quo_get_env(quo)) #> #> ── Skipped tests (1) ───────────────────────────────────────────────────── #> • This test hasn't been written yet (1): test-success.R:6:3 #> #> #> [ FAIL 0 | WARN 1 | SKIP 1 | PASS 4 ] test_file(path, desc = \"some tests have warnings\") #> #> ══ Testing test-success.R ════════════════════════════════════════════════ #> #> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 1 | SKIP 0 | PASS 0 ] #> [ FAIL 0 | WARN 1 | SKIP 0 | PASS 1 ] #> #> ── Warning (test-success.R:10:3): some tests have warnings ───────────────────── #> NaNs produced #> Backtrace: #> ▆ #> 1. └─testthat::expect_equal(log(-1), NaN) at test-success.R:10:3 #> 2. └─testthat::quasi_label(enquo(object), label, arg = \"object\") #> 3. └─rlang::eval_bare(expr, quo_get_env(quo)) #> #> [ FAIL 0 | WARN 1 | SKIP 0 | PASS 1 ] test_file(path, reporter = \"minimal\") #> .SW..."},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":null,"dir":"Reference","previous_headings":"","what":"Run all tests in a package — test_package","title":"Run all tests in a package — test_package","text":"test_local() tests local source package. test_package() tests installed package. test_check() checks package R CMD check. See vignette(\"special-files\") learn various files testthat works .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run all tests in a package — test_package","text":"","code":"test_package(package, reporter = check_reporter(), ...) test_check(package, reporter = check_reporter(), ...) test_local(path = \".\", reporter = NULL, ..., load_package = \"source\")"},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run all tests in a package — test_package","text":"package tests belong package, name package. reporter Reporter use summarise output. Can supplied string (e.g. \"summary\") R6 object (e.g. SummaryReporter$new()). See Reporter details list built-reporters. ... Additional arguments passed test_dir() path Path directory containing tests. load_package Strategy use load package code: \"none\", default, load package. \"installed\", uses library() load installed package. \"source\", uses pkgload::load_all() source package. configure arguments passed load_all(), add field DESCRIPTION file:","code":"Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)"},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run all tests in a package — test_package","text":"list (invisibly) containing data test results.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"r-cmd-check","dir":"Reference","previous_headings":"","what":"R CMD check","title":"Run all tests in a package — test_package","text":"run testthat automatically R CMD check, make sure tests/testthat.R contains:","code":"library(testthat) library(yourpackage) test_check(\"yourpackage\")"},{"path":"https://testthat.r-lib.org/dev/reference/test_package.html","id":"environments","dir":"Reference","previous_headings":"","what":"Environments","title":"Run all tests in a package — test_package","text":"test run clean environment keep tests isolated possible. package tests, environment inherits package's namespace environment, tests can access internal functions objects.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":null,"dir":"Reference","previous_headings":"","what":"Locate a file in the testing directory — test_path","title":"Locate a file in the testing directory — test_path","text":"Many tests require external file (e.g. .csv testing data import function) working directory varies depending way running test (e.g. interactively, devtools::test(), R CMD check). test_path() understands variations automatically generates path relative tests/testthat, regardless directory might reside relative current working directory.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Locate a file in the testing directory — test_path","text":"","code":"test_path(...)"},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Locate a file in the testing directory — test_path","text":"... Character vectors giving path components.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Locate a file in the testing directory — test_path","text":"character vector giving path.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_path.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Locate a file in the testing directory — test_path","text":"","code":"if (FALSE) { test_path(\"foo.csv\") test_path(\"data\", \"foo.csv\") }"},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":null,"dir":"Reference","previous_headings":"","what":"Run a test — test_that","title":"Run a test — test_that","text":"test encapsulates series expectations small, self-contained unit functionality. test contains one expectations, expect_equal() expect_error(), lives test/testhat/test* file, often together tests relate function set functions. test execution environment, object created test also dies test. Note cleanup happen automatically aspects global state, session options filesystem changes. Avoid changing global state, possible, reverse changes make.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run a test — test_that","text":"","code":"test_that(desc, code)"},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run a test — test_that","text":"desc Test name. Names brief, evocative. common write description reads like natural sentence, e.g. test_that(\"multiplication works\", { ... }). code Test code containing expectations. Braces ({}) always used order get accurate location data test failures.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run a test — test_that","text":"run interactively, returns invisible(TRUE) tests pass, otherwise throws error.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/test_that.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run a test — test_that","text":"","code":"test_that(\"trigonometric functions match identities\", { expect_equal(sin(pi / 4), 1 / sqrt(2)) expect_equal(cos(pi / 4), 1 / sqrt(2)) expect_equal(tan(pi / 4), 1) }) #> Test passed if (FALSE) { test_that(\"trigonometric functions match identities\", { expect_equal(sin(pi / 4), 1) }) }"},{"path":"https://testthat.r-lib.org/dev/reference/testthat-package.html","id":null,"dir":"Reference","previous_headings":"","what":"An R package to make testing fun! — testthat-package","title":"An R package to make testing fun! — testthat-package","text":"Try example . look references learn function documentation test_that().","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat-package.html","id":"options","dir":"Reference","previous_headings":"","what":"Options","title":"An R package to make testing fun! — testthat-package","text":"testthat.use_colours: output coloured? (Default: TRUE). testthat.summary.max_reports: maximum number detailed test reports printed summary reporter (default: 10). testthat.summary.omit_dots: Omit progress dots summary reporter (default: FALSE).","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/testthat-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"An R package to make testing fun! — testthat-package","text":"Maintainer: Hadley Wickham hadley@posit.co contributors: Posit Software, PBC [copyright holder, funder] R Core team (Implementation utils::recover()) [contributor]","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve paths to built-in example test files — testthat_examples","title":"Retrieve paths to built-in example test files — testthat_examples","text":"testthat_examples() retrieves path directory test files, testthat_example() retrieves path single test file.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve paths to built-in example test files — testthat_examples","text":"","code":"testthat_examples() testthat_example(filename)"},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Retrieve paths to built-in example test files — testthat_examples","text":"filename Name test file","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_examples.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Retrieve paths to built-in example test files — testthat_examples","text":"","code":"dir(testthat_examples()) #> [1] \"_snaps\" \"test-failure.R\" \"test-success.R\" testthat_example(\"success\") #> [1] \"/home/runner/work/_temp/Library/testthat/examples/test-success.R\""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"Create testthat_results object test results stored ListReporter results field.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"","code":"testthat_results(results)"},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"results list stored ListReporter","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_results.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a testthat_results object from the test results\nas stored in the ListReporter results field. — testthat_results","text":"list argument testthat_results object","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/testthat_tolerance.html","id":null,"dir":"Reference","previous_headings":"","what":"Default numeric tolerance — testthat_tolerance","title":"Default numeric tolerance — testthat_tolerance","text":"testthat's default numeric tolerance 1.4901161 × 10-8.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/testthat_tolerance.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default numeric tolerance — testthat_tolerance","text":"","code":"testthat_tolerance()"},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":null,"dir":"Reference","previous_headings":"","what":"Try evaluating an expressing multiple times until it succeeds. — try_again","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"Try evaluating expressing multiple times succeeds.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"","code":"try_again(times, code)"},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"times Maximum number attempts. code Code evaluate","code":""},{"path":"https://testthat.r-lib.org/dev/reference/try_again.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Try evaluating an expressing multiple times until it succeeds. — try_again","text":"","code":"third_try <- local({ i <- 3 function() { i <<- i - 1 if (i > 0) fail(paste0(\"i is \", i)) } }) try_again(3, third_try())"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":null,"dir":"Reference","previous_headings":"","what":"Use Catch for C++ Unit Testing — use_catch","title":"Use Catch for C++ Unit Testing — use_catch","text":"Add necessary infrastructure enable C++ unit testing R packages Catch testthat.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Use Catch for C++ Unit Testing — use_catch","text":"","code":"use_catch(dir = getwd())"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Use Catch for C++ Unit Testing — use_catch","text":"dir directory containing R package.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Use Catch for C++ Unit Testing — use_catch","text":"Calling use_catch() : Create file src/test-runner.cpp, ensures testthat package understand run package's unit tests, Create example test file src/test-example.cpp, showcases might use Catch write unit test, Add test file tests/testthat/test-cpp.R, ensures testthat run compiled tests invocations devtools::test() R CMD check, Create file R/catch-routine-registration.R, ensures R automatically register routine tools::package_native_routine_registration_skeleton() invoked. also need : Add xml2 Suggests, e.g. usethis::use_package(\"xml2\", \"Suggests\") Add testthat LinkingTo, e.g. usethis::use_package(\"testthat\", \"LinkingTo\") C++ unit tests can added C++ source files within src directory package, format similar R code tested testthat. simple example unit test written testthat + Catch: package compiled, unit tests alongside harness running tests compiled R package, C entry point run_testthat_tests(). testthat use entry point run unit tests detected.","code":"context(\"C++ Unit Test\") { test_that(\"two plus two is four\") { int result = 2 + 2; expect_true(result == 4); } }"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Use Catch for C++ Unit Testing — use_catch","text":"functions provided Catch available CATCH_ prefix -- see full list. testthat provides following wrappers, conform testthat's R interface: general, prefer using testthat wrappers, testthat also work ensure unit tests within compiled run using Solaris Studio compilers (currently unsupported Catch). make easier submit packages CRAN use Catch.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"symbol-registration","dir":"Reference","previous_headings":"","what":"Symbol Registration","title":"Use Catch for C++ Unit Testing — use_catch","text":"opted disable dynamic symbol lookup package, need explicitly export symbol package testthat can use run unit tests. testthat look routine one names: See Controlling Visibility Registering Symbols Writing R Extensions manual information.","code":"C_run_testthat_tests c_run_testthat_tests run_testthat_tests"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"advanced-usage","dir":"Reference","previous_headings":"","what":"Advanced Usage","title":"Use Catch for C++ Unit Testing — use_catch","text":"like write Catch test runner, can instead use testthat::catchSession() object file form: can useful like run unit tests custom arguments passed Catch session.","code":"#define TESTTHAT_TEST_RUNNER #include void run() { Catch::Session& session = testthat::catchSession(); // interact with the session object as desired }"},{"path":"https://testthat.r-lib.org/dev/reference/use_catch.html","id":"standalone-usage","dir":"Reference","previous_headings":"","what":"Standalone Usage","title":"Use Catch for C++ Unit Testing — use_catch","text":"like use C++ unit testing facilities provided Catch, prefer use regular testthat R testing infrastructure, can manually run unit tests inserting call : necessary within unit test suite.","code":".Call(\"run_testthat_tests\", PACKAGE = )"},{"path":[]},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":null,"dir":"Reference","previous_headings":"","what":"Verify output — verify_output","title":"Verify output — verify_output","text":"function superseded favour expect_snapshot() friends. regression test records interwoven code output file, similar way knitting .Rmd file (see caveats ). verify_output() designed particularly testing print methods error messages, primary goal ensure output helpful human. Obviously, test code, best can make results explicit saving text file. makes output easy verify code reviews, ensures change output accident. verify_output() designed used git: see changed previous run, need use git diff similar.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Verify output — verify_output","text":"","code":"verify_output( path, code, width = 80, crayon = FALSE, unicode = FALSE, env = caller_env() )"},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Verify output — verify_output","text":"path Path record results. usually call test_path() order ensure path used run interactively (working directory typically project root), run automated test (working directory tests/testthat). code Code execute. usually multiline expression contained within {} (similarly test_that() calls). width Width console output crayon Enable cli/crayon package colouring? unicode Enable cli package UTF-8 symbols? set TRUE, call skip_if(!cli::is_utf8_output()) disable test CI platforms support UTF-8 (e.g. Windows). env environment evaluate code .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"syntax","dir":"Reference","previous_headings":"","what":"Syntax","title":"Verify output — verify_output","text":"verify_output() can capture abstract syntax tree, losing whitespace comments. mildly offset limitation: Strings converted R comments output. Strings starting # converted headers output.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/verify_output.html","id":"cran","dir":"Reference","previous_headings":"","what":"CRAN","title":"Verify output — verify_output","text":"CRAN, verify_output() never fail, even output changes. avoids false positives tests print methods error messages often fragile due implicit dependencies packages, failure imply incorrect computation, just change presentation.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":null,"dir":"Reference","previous_headings":"","what":"Watch a directory for changes (additions, deletions & modifications). — watch","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"used power auto_test() auto_test_package() functions used rerun tests whenever source code changes.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"","code":"watch(path, callback, pattern = NULL, hash = TRUE)"},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"path character vector paths watch. Omit trailing backslash. callback function called everytime change occurs. three parameters: added, deleted, modified, return TRUE keep watching, FALSE stop. pattern file pattern passed dir() hash hashes accurate detecting changes, slower large files. FALSE, uses modification time stamps","code":""},{"path":"https://testthat.r-lib.org/dev/reference/watch.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Watch a directory for changes (additions, deletions & modifications). — watch","text":"Use Ctrl + break (windows), Esc (mac gui) Ctrl + C (command line) stop watcher.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":null,"dir":"Reference","previous_headings":"","what":"Mock functions in a package. — with_mock","title":"Mock functions in a package. — with_mock","text":"with_mock() local_mock() superseded favour with_mocked_bindings() local_mocked_bindings(). works using C code temporarily modify mocked function place. abusive R's internals, makes dangerous, longer recommended.","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Mock functions in a package. — with_mock","text":"","code":"with_mock(..., .env = topenv()) local_mock(..., .env = topenv(), .local_envir = parent.frame())"},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Mock functions in a package. — with_mock","text":"... named parameters redefine mocked functions, unnamed parameters evaluated mocking functions .env environment patch functions, defaults top-level environment. character interpreted package name. .local_envir Environment add exit handler. expert use .","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Mock functions in a package. — with_mock","text":"result last unnamed parameter","code":""},{"path":"https://testthat.r-lib.org/dev/reference/with_mock.html","id":"-rd-edition","dir":"Reference","previous_headings":"","what":"3rd edition","title":"Mock functions in a package. — with_mock","text":"with_mock() local_mock() deprecated third edition.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-development-version","dir":"Changelog","previous_headings":"","what":"testthat (development version)","title":"testthat (development version)","text":"test_file(desc = ) now find describe() tests well testthat() tests (#1903). JunitReporter() now uses ensures numeric values saved xml file . decimal separator. (@maksymiuks, #1660)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-320","dir":"Changelog","previous_headings":"","what":"testthat 3.2.0","title":"testthat 3.2.0","text":"CRAN release: 2023-10-06","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"lifecycle-changes-3-2-0","dir":"Changelog","previous_headings":"","what":"Lifecycle changes","title":"testthat 3.2.0","text":"is_informative_error() wrap argument test_dir() friends now defunct. expect_no_error(), expect_no_warning(), expect_no_message(), expect_no_condition(), local_mocked_bindings(), with_mocked_bindings() now stable, experimental.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-features-3-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"testthat 3.2.0","text":"packages, regardless whether use rlang 1.0.0, now use new snapshot display errors, warnings, messages (#1856). longer shows class name, instead focussing display closely mimics ’ll see interactively, including showing error call. testthat uses improved algorithm finding srcref associated expectation/error/warning/skip. now looks recent call known source found inside test_that() call. generally gives specific locations previous approach gives much better locations error occurs exit handler.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-features-and-bug-fixes-3-2-0","dir":"Changelog","previous_headings":"","what":"Minor features and bug fixes","title":"testthat 3.2.0","text":"Helpers longer run twice. expect_setequal() correctly displays results one actual expected missing elements (#1835). expect_snapshot() friends longer create temporary file every invocation. expect_snapshot_file() now generates clickable links review changes (#1821). expect_snapshot_value() improved error object can’t safely serialized using specified style (#1771). options(rlang_interactive = TRUE) longer causes skip_on_cran() run CRAN (#1868). skip_if_offline() now errors don’t curl installed (#1854). StopReporter gains ability suppress praise test passes. ProgressReporter now uses two characters wide skip column order consistent width 10 tests skipped single file (@mgirlich, #1844). test_file() gains desc argument allows run single test file (#1776).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-3110","dir":"Changelog","previous_headings":"","what":"testthat 3.1.10","title":"testthat 3.1.10","text":"CRAN release: 2023-07-06 Fix upcoming R-devel release. testthat now sets _R_CHECK_BROWSER_NONINTERACTIVE_ environment variable running tests. ensure left-browser() statements trigger error encountered running tests. functionality enabled R (>= 4.3.0). (#1825)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-319","dir":"Changelog","previous_headings":"","what":"testthat 3.1.9","title":"testthat 3.1.9","text":"CRAN release: 2023-06-15 New expect_contains() expect_in() works similarly expect_true((expected %% object)) expect_true((object %% expected)) give informative failure messages (#1346). New is_snapshot() returns TRUE code running inside snapshot test (#1796) is_checking() returns TRUE test running inside R CMD check (#1795) ProgressReporter reports run time test files take longer 1s, rather 0.1s. (#1806) re-displays failures end results. Skips now shown end reporter summaries, tests run. makes less intrusive interactive tests still allowing verify correct tests skipped (#1801). using parallel tests, links failed tests (#1787) links accept/review snapshot (#1802) now work. set_state_inspector() allows register function ’s called every test, reporting differences. useful detecting tests made changes global state (like options, env vars, connections) (#1674). function inspired renv’s testing infrastructure. skip_on_cran() longer skips (errors) run interactively. teardown_env() works cases. testthat longer truncates tracebacks uses rlang’s default tree display.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-318","dir":"Changelog","previous_headings":"","what":"testthat 3.1.8","title":"testthat 3.1.8","text":"CRAN release: 2023-05-04 expect_snapshot() differences longer use quotes. expect_error(), expect_warning(), expect_message() now correctly enforce condition expected base class (e.g. error, warning, message) even class argument used (#1168). () now calls local_test_context() behaves similarly test_that() (#1731), now exported can easily run BDD tests interactively (#1587) skip_on_bioc() now uses documented environment variable (IS_BIOC_BUILD_MACHINE) (#1712). source_file(), used various parts helper setup/teardown machinery, now reports file name case errors (#1704). test_path() now works called within helper files (#1562). New vignette(\"special-files\") describes various special files testthat uses (#1638). with_mocked_bindings() local_mocked_bindings() now also bind imports namespace can mock S3 methods. changes make good substitutes deprecated functions with_mock() local_mock(), older functions now recommend switching newer equivalents instead using mockr mockery packages.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-317","dir":"Changelog","previous_headings":"","what":"testthat 3.1.7","title":"testthat 3.1.7","text":"CRAN release: 2023-03-12 expect_setequal() gives actionable feedback (#1657). expect_snapshot() longer elides new lines run interactively (#1726). Experimental new with_mocked_bindings() local_mocked_bindings() (#1739).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-316","dir":"Changelog","previous_headings":"","what":"testthat 3.1.6","title":"testthat 3.1.6","text":"CRAN release: 2022-12-09 embedded version Catch longer uses sprintf().","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-315","dir":"Changelog","previous_headings":"","what":"testthat 3.1.5","title":"testthat 3.1.5","text":"CRAN release: 2022-10-08 Deprecation warnings longer captured expect_warning(code, NA), expect_no_warning(code), expect_silent(code). ensures bubble top level can address (#1680). want assert code throw deprecation warning, use expect_no_condition(code(), class = \"lifecycle_warning_deprecation\"). New experimental expect_no_error(), expect_no_warning(), expect_no_message(), expect_no_condition() asserting code runs without error, warning, message, condition (#1679). Fixed warning R >=4.2.0 Windows occurred using C++ testing infrastructure testthat provides (#1672). Fixed issue prevent compilation Catch unit tests LLVM 15. interim, packages needing local workaround can set PKG_CPPFLAGS = -DCATCH_CONFIG_CPP11_NO_SHUFFLE src/Makevars. (2, #1687) Improve way capture_output() handles encoding thanks suggestion Kurt Hornik (#1693). means snapshots using UTF-8 encoded text windows work . local_reproducible_output() longer attempt set local language LANG='C' set R version used compiled natural language support (NLS), previously emit non-test-related warnings testing (@dgkf, #1662; @heavywatal, #1689). test_check() now suppresses hyperlinks since ’ll take wrong places (#1648). New set_max_fails() helper make easier set maximum number failures stopping test suite. advice set Inf now clickable (#1628). can now configure behaviour implicit devtools::load_all() call performed devtools::test() package DESCRIPTION file (#1636). disable exports internal functions testthat helpers, use: Helpers now attached search path default calling devtools::test().","code":"Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-314","dir":"Changelog","previous_headings":"","what":"testthat 3.1.4","title":"testthat 3.1.4","text":"CRAN release: 2022-04-26 Minor tweaks output latest cli (#1606).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-313","dir":"Changelog","previous_headings":"","what":"testthat 3.1.3","title":"testthat 3.1.3","text":"CRAN release: 2022-03-29 Package explicitly depend rlang description file now opting new snapshot display errors, warnings, messages. Previously concerned packages explicitly depended rlang >= 1.0.0. display eventually become default packages. Changes include: Condition classes longer included snapshot default. avoid snapshot noise upstream code adds changes class. instance, r-devel added classes base errors. Warnings errors now printed rlang, including call field. makes easy monitor full appearance warning error messages displayed users. change part push towards mentioning useful context error part messages, see release notes rlang 1.0.0 . Test results show hyperlinks failed expectation supported (#1544).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-312","dir":"Changelog","previous_headings":"","what":"testthat 3.1.2","title":"testthat 3.1.2","text":"CRAN release: 2022-01-20 testthat now uses brio reading writing (#1120). ensures snapshots always use “” separate lines (#1516). expect_snapshot() longer inadvertently trims trailing new lines errors messages (#1509). expect_snapshot() generates snapshot different value still compares equal (e.g. ’ve set numeric tolerance), saved values longer update another snapshot file changes. expect_snapshot() now adds .new file variants actually changed, variants, expect_snapshot_file() variant longer immediately deletes .new files (#1468). expect_snapshot_file() gains transform argument match expect_snapshot() (#1474). compare now defaults NULL, automatically guessing comparison type based extension. expect_snapshot_file() now errors file snapshot exist; SnapshotReporter also now treats file directory absolute path (#1476, @malcolmbarrett) New expect_snapshot_warning() match expect_snapshot_error() (#1532). JUnitReporter now includes skip messages/reasons (@rfineman, #1507) local_reproducible_output() gains lang argument can optionally override language used translate error messages (#1483). also sets global option cli.num_colors addition crayon.enabled. test_that() longer inappropriately skips calling expect_equal() ’ve temporarily set locale non-UTF-8 (#1285). skip_if_offline() now automatically calls skip_on_cran() (#1479). snapshot_accept() snapshot_review() now work exactly file specification can snapshot name, file name, directory (#1546). work better variants (#1508). Snapshot cleanup also removes empty directories (#1457). snapshot changes hint also mentions can use snapshot_review() (#1500, @DanChaltiel) message tells variant active (#1540). JUnit reporter now includes skip messages/reasons (@rfineman, #1507).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-311","dir":"Changelog","previous_headings":"","what":"testthat 3.1.1","title":"testthat 3.1.1","text":"CRAN release: 2021-12-03 Condition expectations like expect_error() now match across ancestry chained errors (#1493). can disable setting new inherit argument FALSE. Added preliminary support rlang 1.0 errors. disabled default time . activate , specify rlang (>= 1.0.0) DESCRIPTION file (>= 0.99.0.9001 ’re using dev version). activated, snapshots now use rlang print error warning messages, including Error: Warning: prefixes. means call field conditions now displayed snapshots present. Parent error messages also displayed. Following change, snapshots including error warning messages need revalidated. enable new rlang 1.0 output unconditionally future release. expect_snapshot() gains new argument cnd_class control whether show class errors, warnings, messages. default currently unchanged condition classes keep included snapshots. However, plan change default FALSE upcoming release prevent distracting snapshot diffing upstream packages add error classes. instance, development version R currently adding classes basic errors, causes spurious snapshot changes testing R-devel CI. depend rlang 1.0 (see ), default already set FALSE. expect_snapshot() longer processes rlang injection operators like !!. Fixed bug expectations long inputs use :: (#1472).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-310","dir":"Changelog","previous_headings":"","what":"testthat 3.1.0","title":"testthat 3.1.0","text":"CRAN release: 2021-10-04","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"snapshot-tests-3-1-0","dir":"Changelog","previous_headings":"","what":"Snapshot tests","title":"testthat 3.1.0","text":"expect_snapshot() longer experimental. expect_snapshot() friends gets experimental new variant argument causes snapshot saved _snaps/{variant}/{test}.md instead _snaps/{test}.md. allows generate (compare) unique snapshots different scenarios like operating system R version (#1143). expect_snapshot() gains transform argument, function takes character vector lines returns modified character vector lines. makes easy remove sensitive (e.g. API keys) stochastic (e.g. random temporary directory names) snapshot output (#1345). expect_snapshot_file() now replaces previous .new snapshot code fails different value. expect_snapshot_value() now explicit tolerance argument uses testthat default, thus making like expect_equal() rather expect_identical(). Set NULL want precise comparisons (#1309). expect_snapshot_value(style = \"deparse\") now works negative values (#1342). test containing multiple snapshots fails (skips) snapshots, later snapshots now silently restored. (Previously warned reset snapshots, just later snapshots). multiple tests name use snapshots (good idea), longer get warning. Instead snapshots aggregated across tests.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"breaking-changes-3-1-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"testthat 3.1.0","text":"Condition expectations now consistently return expected condition instead return value (#1371). Previously, return condition return value NULL, leading inconsistent behaviour. breaking change 3rd edition. previously : must now use condition expectations outside: breaking change makes testthat consistent. also makes possible inspect value warning, otherwise require additional tools.","code":"expect_equal(expect_warning(f(), \"warning\"), \"value\") expect_warning(expect_equal(f(), \"value\"), \"warning\") # Equivalently, save the value before inspection expect_warning(value <- f(), \"warning\") expect_equal(value, \"value\")"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-3-1-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 3.1.0","text":"Errors test blocks now display call stored condition object (#1418). Uncaught errors now show class (#1426). Multi-line skips show first line skip summary. expr_label(), used concisely describe expressions used expectations, now better job summarising infix function (#1442). local_reproducible_output() now sets max.print option 99999 (default), tests unaffected changes might’ve made .Rprofile (1367). ProgressReporter (default ) now stops end file; ensures see results related tests, ensures snapshots handled consistently (#1402). ProgressReporter now uses env var adjust maximum number failures. makes easier adjust tests run subprocess, common using RStudio (#1450). skip_on_os() gains arch argument can also choose skip selected architectures (#1421). test_that() now correctly errors expectation fails run interactively (#1430). test_that() now automatically correctly generate “empty test” skip generates warnings messages (doesn’t contain expectations). testthat_tolerance() longer unused argument.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-304","dir":"Changelog","previous_headings":"","what":"testthat 3.0.4","title":"testthat 3.0.4","text":"CRAN release: 2021-07-01 vendored Catch code used use_catch() now uses constant value stack size rather relying SIGSTKSZ. fixes compatibility recent glibc versions SIGSTKSZ longer constant. Fixed issue caused errors early termination tests R <= 3.6 failing condition expectation signalled inside snapshot.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-303","dir":"Changelog","previous_headings":"","what":"testthat 3.0.3","title":"testthat 3.0.3","text":"CRAN release: 2021-06-16 expect_snapshot_file() gains compare argument (#1378, @nbenn). customisation point compare old new snapshot files. functions compare_file_binary() compare_file_text() now exported testthat supplied compare argument. implement behaviour old binary argument now deprecated. expect_snapshot() longer deletes snapshots unexpected error occurs. New announce_snapshot_file() function developers testthat extensions. Announcing snapshot file allows testthat preserve files generated unexpected error skip() (#1393). Unannounced files automatically deleted cleanup generating code isn’t called. New expectation: expect_no_match(). complements expect_match() checking string doesn’t match regular expression (@michaelquinn32, #1381). Support setting testthat edition via environment variable (TESTTHAT_EDITION) well (@michaelquinn32, #1386).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-302","dir":"Changelog","previous_headings":"","what":"testthat 3.0.2","title":"testthat 3.0.2","text":"CRAN release: 2021-02-14 Failing expectations now include backtrace ’re called directly within test_that() instead wrapped helper function (#1307). CheckReporter now records warnings CRAN. Otherwise failed CRAN revdep checks tend cluttered warnings (#1300). automatically cleans testthat-problems.rds left previous runs latest run successful (#1314). expect_s3_class() expect_s4_class() can now check object isn’t S3 S4 object supplying NA second argument (#1321). expect_s3_class() expect_s4_class() format class names less confusing way (#1322). expect_snapshot() collapses multiple adjacent headings , , e.g., multiple lines code row, ’ll see one “Code:” heading (#1311).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-301","dir":"Changelog","previous_headings":"","what":"testthat 3.0.1","title":"testthat 3.0.1","text":"CRAN release: 2020-12-17 New testthat.progress.verbose_skips option. Set FALSE stop reporting skips occur; still appear summary (#1209, @krlmlr). CheckReporter results tweaked based experiences running R CMD check many packages. Hopefully now easier see biggest problems (.e. failures errors) still skips warnings available check needed (#1274). now full test name always shown, matter long (#1268). Catch C++ tests longer reported multiple times (#1237) automatically skipped Solaris since Catch supported (#1257). use_catch() makes clear package needs suggest xml2 (#1235). auto_test_package() works (@mbojan, #1211, #1214). expect_snapshot() gains new error argument controls whether error expected. unexpected error thrown, expected error thrown, expect_snapshot() fail (even CRAN) (#1200). expect_snapshot_value(style = \"deparse\") handles common R data structures. expect_snapshot_value() now passes ... waldo::compare() (#1222). expect_snapshot_file() gives hint next steps failure occurs non-interactive environments (help @maelle, #1179). expect_snapshot_*() gives informative hint ’re running tests interactively (#1226). expect_snapshot_*() automatically removes _snaps directory ’s empty (#1180). also warns snapshots discarded tests duplicated names (#1278, @krlmlr). local_reproducible_output() now sets LANGUAGE env var “en”. matches behaviour R CMD check interactive settings (#1213). also now unsets RSTUDIO envvar, instead setting 0 (#1225). RstudioReporter renamed RStudioReporter. skip_if_not() longer appends “TRUE” custom messages (@dpprdan, #1247). test_that() now warns (3e ) code doesn’t braces, since makes hard track source error (#1280, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-300","dir":"Changelog","previous_headings":"","what":"testthat 3.0.0","title":"testthat 3.0.0","text":"CRAN release: 2020-10-31","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"id_3rd-edition-3-0-0","dir":"Changelog","previous_headings":"","what":"3rd edition","title":"testthat 3.0.0","text":"testhat 3.0.0 brings 3rd edition makes number breaking changes order clean interface help use latest recommendations. opt-3rd edition package, set Config/testthat/edition: 3 DESCRIPTION use local_edition(3) individual tests. can retrieve active edition edition_get(). Learn vignette(\"third-edition\"). context() deprecated. expect_identical() expect_equal() use waldo::compare() compare actual expected results. mostly yields much informative output actual expected values different, writing uncovered bugs existing comparison code. expect_error(), expect_warning(), expect_message(), expect_condition() now use underlying logic: capture first condition matches class/regexp allow anything else bubble (#998/#1052). also warn unexpected arguments never used. argument expect_message() expect_warning() now deprecated. never particularly good idea well documented, now superseded new condition capturing behaviour. expect_equivalent(), expect_reference(), expect_is() expect_that() deprecated. Messages longer automatically silenced. Either use suppressMessages() hide unimportant messages, expect_message() catch important messages (#1095). setup() teardown() deprecated favour test fixtures. See vignette(\"test-fixtures\") details. expect_known_output(), expect_known_value(), expect_known_hash(), expect_equal_to_reference() deprecated favour expect_snapshot_output() expect_snapshot_value(). test_that() now sets number options env vars make output reproducible possible (#1044). Many options previously set various places (devtools::test(), test_dir(), test_file(), verify_output()) now centralised. can use code, debugging tests interactively local_test_context(). with_mock() local_mock() deprecated; please use mockr mockery packages instead (#1099).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"snapshot-testing-3-0-0","dir":"Changelog","previous_headings":"","what":"Snapshot testing","title":"testthat 3.0.0","text":"New family snapshot expectations (expect_snapshot(), expect_snapshot_output(), expect_snapshot_error(), expect_snapshot_value()) provide “snapshot” tests, expected results stored separate files test/testthat/_snaps. ’re useful whenever ’s painful store expected results directly test files. expect_snapshot_file() along snapshot_review() help snapshot complex data, initial support text files, images, data frames (#1050). See vignette(\"snapshotting\") details.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-3-0-0","dir":"Changelog","previous_headings":"","what":"Reporters","title":"testthat 3.0.0","text":"CheckReporter (used inside R CMD check) now prints problems (.e. errors, failures, warnings skips; just first 10), lists skips types, records problems machine readable format tests/testthat-problems.rds (#1075). New CompactProgressReporter tweaks output ProgressReporter use single file, devtools::test_file(). can pick different default setting testthat.default_compact_reporter name reporter. ProgressReporter (default reporter) now keeps stack traces errors happen test, making problems substantially easier track (#1004). checks ’ve exceeded maximum number failures (option testthat.progress.max_fails) expectation, rather end file (#967). also gains new random praise options use emoji, lists skipped tests type (#1028). StopReporter adds random praise emoji single test passes (#1094). refined display failures, now using style CompactProgressReporter ProgressReporter. SummaryReporter now records file start, just context start. makes compatible modern style use context() (#1089). reporters now use exactly format reporting location expectation. Warnings now include backtrace, making easier figure came . Catch C++ tests now provide detailed results test. upgrade existing code, re-run testthat::use_catch() (#1008). Many reporters (e.g. check reporter) longer raise error tests fail. Use stop_on_failure argument devtools::test() testthat::test_dir() code relies . Alternatively, use reporter = c(\"check\", \"fail\") e.g. create failing check reporter.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"fixtures-3-0-0","dir":"Changelog","previous_headings":"","what":"Fixtures","title":"testthat 3.0.0","text":"New vignette(\"test-fixtures\") describes test fixtures; .e. temporarily cleanly change global state order test parts code otherwise hard run (#1042). setup() teardown() superseded favour test fixtures. New teardown_env() use withr::defer(). allows run code tests run.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"skips-3-0-0","dir":"Changelog","previous_headings":"","what":"Skips","title":"testthat 3.0.0","text":"New vignette(\"skipping\") gives general information skipping tests, include basics testing skipping helpers (#1060). ProgressReporter() CheckReporter() list number skipped tests reason end reporter. makes easier check ’re skipping wrong tests, particularly CI services (#1028).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"test-running-3-0-0","dir":"Changelog","previous_headings":"","what":"Test running","title":"testthat 3.0.0","text":"test_that() longer triggers error run outside tests; instead produces informative summary failures, errors, warnings, skips occurred inside test. test_that() now errors desc string (#1161). test_file() now runs helper, setup, teardown code, arguments test_dir() (#968). Long deprecated encoding argument removed. test_dir() now defaults stop_on_failure TRUE consistency test_ functions. wrap argument deprecated; ’s clear ever exposed. New test_local() tests local source package directory. ’s equivalent devtools::test() doesn’t require devtools dependencies installed (#1030).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-3-0-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 3.0.0","text":"testthat longer supports tests stored inst/tests. deprecated since testthat 0.11.0 (released 2015). test_package() (previously used running tests R CMD check) fail silently tests found avoid breaking old packages CRAN (#1149). capture_output() verify_output() use new testthat_print() generic. allows control printed representation object specifically tests (.e. usual print method shows data varies way don’t care tests) (#1056). context_start_file() now exported external reporters (#983, #1082). now strips first instance prefix/suffix (#1041, @stufield). expect_error() longer encourages use class. advice removes one type fragility expense creating different type (#1013). expect_known_failure() removed. far can tell ever used testthat, rather fragile. expect_true(), expect_false(), expect_null() now use waldo produce informative failures. verify_output() longer always fails output contains carriage return character (“) (#1048). uses pdf() device instead png() works systems without X11 (#1011). uses waldo::compare() give informative failures.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-232","dir":"Changelog","previous_headings":"","what":"testthat 2.3.2","title":"testthat 2.3.2","text":"CRAN release: 2020-03-02 Fix R CMD check issues","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-231","dir":"Changelog","previous_headings":"","what":"testthat 2.3.1","title":"testthat 2.3.1","text":"CRAN release: 2019-12-01 last version testthat introduced performance regression error assertions (#963). fix , need install rlang 0.4.2. Fixed error assertions rJava errors (#964). Fixed issue error warning messages retrieved conditionMessage() certain circumstances.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-230","dir":"Changelog","previous_headings":"","what":"testthat 2.3.0","title":"testthat 2.3.0","text":"CRAN release: 2019-11-05","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"conditions-2-3-0","dir":"Changelog","previous_headings":"","what":"Conditions","title":"testthat 2.3.0","text":"release mostly focusses overhaul testthat works conditions (.e. errors, warnings messages). relatively user-facing changes, although now see informative backtraces errors failures. Unexpected errors now printed simplified backtrace. expect_error() expect_condition() now display backtrace error doesn’t conform expectations (#729). expect_error(), expect_warning() expect_message() now call conditionMessage() get condition message. generic makes possible generate messages print-time rather signal-time. expect_error() gets better warning message test custom error class regexp. New exp_signal() function condition signaller implements testthat protocol (signal stop() expectation broken, continue_test restart). Existence restarts first checked invocation. makes possible signal warnings messages different condition signaller (#874). ListReporter now tracks expectations errors, even occur outside tests. ensures stop_on_failure matches results displayed reporter (#936). can silence warnings untested error classes implementing method is_uninformative_warning(). method lazily registered, e.g. vctrs::s3_register(). useful introducing experimental error class without encouraging users depend class tests. Respect options(warn = -1) ignore warnings (@jeroen #958).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"expectations-2-3-0","dir":"Changelog","previous_headings":"","what":"Expectations","title":"testthat 2.3.0","text":"Expectations can now explicitly subclassed new_expectation(). constructor follows new conventions S3 classes takes optional subclass optional attributes. Unquoted inputs longer potentially generate multiple test messages (#929). verify_output() longer uses quasiquotation, fixes issues verifying output tidy eval functions (#945). verify_output() gains unicode parameter turn use Unicode characters cli package. disabled default prevent tests failing platforms like Windows don’t support UTF-8 (contributors’ CI machines). verify_output() now correctly handles multi-line condition messages. verify_output() now adds spacing condition messages, consistent spacing added normal output. verify_output() new syntax inserting headers output files: insert \"# Header\" string (starting # Markdown) add header set outputs.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-minor-improvements-and-bug-fixes-2-3-0","dir":"Changelog","previous_headings":"","what":"Other minor improvements and bug fixes","title":"testthat 2.3.0","text":"compare.numeric() uses sophisticated default tolerance automatically skip tests rely numeric tolerance long doubles available (#940). JunitReporter now reports tests ISO 8601 UTC timezone uses maximum precision 3 decimal places (#923).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-221","dir":"Changelog","previous_headings":"","what":"testthat 2.2.1","title":"testthat 2.2.1","text":"CRAN release: 2019-07-25 Repair regression test_rd() add couple tests hopefully detect problem earlier future.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-220","dir":"Changelog","previous_headings":"","what":"testthat 2.2.0","title":"testthat 2.2.0","text":"CRAN release: 2019-07-22","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-features-2-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"testthat 2.2.0","text":"New verify_output() designed testing output aimed humans (commonly print methods error messages). regression test saves output way makes easy review. automatically skipped CRAN (#782, #834).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-2-2-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 2.2.0","text":".data.frame.testthat_results() now always returns data frame 13 columns (@jozefhajnala, #887). auto_test_package() now correctly handles helper files (tests/testthat/helper-*.R), automatically reloading code rerunning tests (@CorradoLanera, #376, #896). expect_match() now displays info even match length 0 (#867). expect_s3_class() gains new exact argument allows check exact class match, just inheritance (#885). fail() succeed() gain info argument, passed along expect(). test_examples() gets minor fixes: now returns results invisibly, doesn’t assume examples contain tests, documents shouldn’t using routinely (#841). test_file() calls Reporter$end_context() context started, fixing error TeamcityReporter (@atheriel, #883). skip() now reports reason skipping : Reason: {skip condition} (@patr1ckm, #868). skip_if() skip_if_not() now report Reason: {skip condition} TRUE Reason: {skip condition} TRUE respectively (@ patr1ckm, #868). skip_if_translated() now tests translation specific message. robust previous approach translation happens message--message, necessarily entire session (#879) (general, ’s impossible determine language R currently using). skip_on_covr() allows skip tests covr running. (@ianmcook, #895) expect_known_value() gains new serialisation version argument, defaulting 2. Prevents .rds files created hold reference objects making package appear require R >= 3.5 (#888 @jennybc).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-211","dir":"Changelog","previous_headings":"","what":"testthat 2.1.1","title":"testthat 2.1.1","text":"CRAN release: 2019-04-23 Fix test failures strict latin1 locale","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-210","dir":"Changelog","previous_headings":"","what":"testthat 2.1.0","title":"testthat 2.1.0","text":"CRAN release: 2019-04-22","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-expectations-2-1-0","dir":"Changelog","previous_headings":"","what":"New expectations","title":"testthat 2.1.0","text":"New expect_visible() expect_invisible() make easier check function call returns result visibly invisibly (#719). New expect_mapequal(x, y) checks x y names, value associated name (.e. compare values vector standardising order names) (#863). New expect_vector() wrapper around vctrs::vec_assert() making easy test vctrs definitions prototype size (#846). (Currently requires development version vctrs.)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"improvements-to-existing-expectations-2-1-0","dir":"Changelog","previous_headings":"","what":"Improvements to existing expectations","title":"testthat 2.1.0","text":"expectations give clearer error messages forget object expected arguments (#743). expect_equal() now correctly compares infinite values (#789). expect_equal_to_reference(), default value update now FALSE (@BrodieG, #683). expect_error() now returns error object documentated (#724). also now warns ’re using classed expectation ’re using class argument. good practice decouples error object (tends stable) rendering user (tends fragile) (#816). expect_identical() gains ... argument pass additional arguments identical() (#714). expect_lt(), expect_lte(), expect_gt() expect_gte() now handle Inf NA arguments appropriately (#732), longer require inputs numeric. expect_output() gains width argument, allowing control output width. inherit getOption(\"width\"), ensuring tests return results regardless environment (#805). expect_setequal() now works vector types (including lists), uses %%, rather sort(). also warns inputs named, suggests mental model expect_setequal() works wrong (#750). is_true() is_false() deprecated conflict functions tidyverse.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-2-1-0","dir":"Changelog","previous_headings":"","what":"Reporters","title":"testthat 2.1.0","text":"Reporter documentation considerably improved (#657). CheckReporter, used R CMD check, now includes count warnings. JUnitReporter longer replaces . class names (#753), creates output compatible Jenkins (#806, @comicfans). ListReporter now records number passed tests original results new columns (#675). ProgressReporter, default reporter, now: Automatically generates context file name. longer recommend use context() instead encourage delete , allowing context autogenerated file name. also eliminates error occurred tests can first context() (#700, #705). Gains update_interval parameter control often updates printed (default 0.1 s). prevents large printing overhead fast tests. (#701, @jimhester) Uses 3 character wide column display test successes, 999 successful tests can displayed without changing alignment (#712). reporter$end_reporter() now called testing completes successfully. ensures don’t get unnecessary output test fails partway (#727).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"skips-2-1-0","dir":"Changelog","previous_headings":"","what":"Skips","title":"testthat 2.1.0","text":"skip_if_offline() skips tests internet connection available (#685). skip_on_ci() skips tests continuous integration systems (@mbjoseph, #825) looking CI env var..","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-new-features-2-1-0","dir":"Changelog","previous_headings":"","what":"Other new features","title":"testthat 2.1.0","text":"New testthat_examples() testthat_example() make easy access new test files bundled package. used various examples make easier understand use package. New local_mock() allows mock function without add additional layer indentation with_mock() (#856).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-minor-improvements-and-bug-fixes-2-1-0","dir":"Changelog","previous_headings":"","what":"Other minor improvements and bug fixes","title":"testthat 2.1.0","text":"auto_test_package() works better recent devtools also watches src/ changes (#809). expect_s3_class() now works unquoting (@jalsalam, #771). expectation objects now contain failure message, even successful (#836) devtools::test() longer fails run multiple times within R session package containing Catch tests. (devtools #1832) New testing_package() retrieves name package currently tested (#699). run_testthat_tests C entrypoint registered robustly. skip() now always produces message length 1, expected elsewhere testthat (#791). Warnings passed even options(warn = 2) set (@yutannihilation, #721).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-201","dir":"Changelog","previous_headings":"","what":"testthat 2.0.1","title":"testthat 2.0.1","text":"CRAN release: 2018-10-13 Fix failing tests devtools 2.0.0","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-200","dir":"Changelog","previous_headings":"","what":"testthat 2.0.0","title":"testthat 2.0.0","text":"CRAN release: 2017-12-13","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"breaking-api-changes-2-0-0","dir":"Changelog","previous_headings":"","what":"Breaking API changes","title":"testthat 2.0.0","text":"“Can’t mock functions base packages”: can longer use with_mock() mock functions base packages, longer works R-devel due changes byte code compiler. recommend using mockery mockr instead. order arguments expect_equivalent() expect_error() changed slightly now pass ... another function. reveals number different errors, like: ‘’ must character vector ‘check.attributes’ must logical ‘tolerance’ numeric argument interpretable logical threw error unexpected class argument “quo” missing, default argument missing, default see one errors, check number, order, names arguments expectation. “Failure: (unknown)”. last release mistakenly failed test bare expectations wrapped inside test_that(). see “(unknown)” failure message, failing expectation previously weren’t seeing. well fixing failure, please also wrap inside test_that() informative name. “Error: argument already evaluated”: way expectations now need create labels changed, caused couple failures unusual usage combined Reduce, lapply(), Map(). Avoid functions favour loops. also recommend reading section quasiquotation support order create informative failure messages.","code":""},{"path":[]},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-and-improved-expectations-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"New and improved expectations","title":"testthat 2.0.0","text":"expect_condition() works like expect_error() captures condition, just error conditions (#621). expect_error() gains class argument allows make assertion class error object (#530). expect_reference() checks two names point object (#622). expect_setequal() compares two sets (stored vectors), ignoring duplicates differences order (#528).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-and-improved-skips-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"New and improved skips","title":"testthat 2.0.0","text":"skip_if() makes easy skip test condition true (#571). example, use skip_if(getRversion() <= 3.1) skip test older R versions. skip_if_translated() skips tests ’re running locale translations likely occur (#565). Use avoid spurious failures checking text error messages non-English locales. skip_if_not_installed() gains new minimum_version argument (#487, #499).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"known-good-values-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"Known good values","title":"testthat 2.0.0","text":"identified useful family expectations compares results expression known good value stored file. designed use conjunction git can see precisely changed, revert needed. expect_known_output() replaces expect_output_file(), soft-deprecated. now defaults update = TRUE warn, rather failing first run. gains print argument automatically print input (#627). also sets width option 80 ensure consistent output across environments (#514) expect_known_value() replaces expect_equal_to_reference(), soft-deprecated. gains update argument defaulting TRUE. changes behaviour previous version, soft-deprecated expect_equal_to_reference() gets update = FALSE. expect_known_failure() stored compares failure message expectation. ’s useful regression test developing informative failure messages expectations.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"quasiquotation-support-2-0-0","dir":"Changelog","previous_headings":"Expectations","what":"Quasiquotation support","title":"testthat 2.0.0","text":"expectations can now use unquoting (#626). makes much easier generate informative failure messages running tests loop. example take test: fails, ’ll see message Error: `f()` equal `* 10`. ’s hard diagnose don’t know iteration caused problem! unquote values using !!, get failure message `f(4L)` equal 40.. much easier diagnose! See ?quasi_label() details. (Note tidy evaluation per se, closely related. time can unquote quosures.)","code":"f <- function(i) if (i > 3) i * 9 else i * 10 for (i in 1:5) { expect_equal(f(i), i * 10) } for (i in 1:5) { expect_equal(f(!!i), !!(i * 10)) }"},{"path":[]},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"setup-and-teardown-2-0-0","dir":"Changelog","previous_headings":"New features","what":"Setup and teardown","title":"testthat 2.0.0","text":"New setup() teardown() functions allow run start end test file. useful want pair cleanup code code messes state (#536). Two new prefixes recognised test/ directory. Files starting setup run tests (unlike helpers run devtools::load_all()). Files starting teardown run tests completed (#589).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-new-features-2-0-0","dir":"Changelog","previous_headings":"New features","what":"Other new features","title":"testthat 2.0.0","text":"files now read written UTF-8 (#510, #605). is_testing() allows tell code run inside testing environment (#631). Rather taking run-time dependency testthat may want inline function package: ’s frequently useful combine interactive().","code":"is_testing <- function() { identical(Sys.getenv(\"TESTTHAT\"), \"true\") }"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-default-reporter-2-0-0","dir":"Changelog","previous_headings":"New features","what":"New default reporter","title":"testthat 2.0.0","text":"new default reporter, ReporterProgress, produces aesthetically pleasing output makes important information available upfront (#529). can return previous default setting options(testthat.default_reporter = \"summary\").","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-2-0-0","dir":"Changelog","previous_headings":"New features","what":"Reporters","title":"testthat 2.0.0","text":"Output colours tweaked consistent clang: warnings now magenta, skips blue. New default_reporter() check_reporter() returns default reporters interactive check environments (#504). New DebugReporter calls better version recover() case failures, errors, warnings (#360, #470). New JunitReporter generates reports JUnit compatible format. (#481, @lbartnik; #640, @nealrichardson; #575) New LocationReporter just prints location every expectation. useful locating segfaults C/C++ breakpoints (#551). SummaryReporter received number smaller tweaks Aborts testing soon limit given option testthat.summary.max_reports (default 10) reached (#520). New option testthat.summary.omit_dots = TRUE hides progress dots speeding tests small amount (#502). Bring back random praise encouragement accidentally dropped (#478). New option testthat.default_check_reporter, defaults \"check\". Continuous Integration system can set option evaluating package test sources order direct test result details known location. reporters now accept file argument initialization. provided, reporters write test results path. output destination can also controlled option testthat.output_file (#635, @nealrichardson).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"deprecated-functions-2-0-0","dir":"Changelog","previous_headings":"","what":"Deprecated functions","title":"testthat 2.0.0","text":"is_null() matches() deprecated conflict functions tidyverse (#523).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-2-0-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 2.0.0","text":"Updated Catch 1.9.6. testthat now understands makes use package routine registration mechanism required CRAN R >= 3.4.0. Better reporting deeply nested failures, limiting stack trace first last 10 entries (#474). Bare expectations notify reporter . achieved running tests inside test_code() default (#427, #498). behaviour can overridden setting wrap = FALSE test_dir() friends (#586). auto_test() auto_test_package() provide hash parameter enable switching faster, time-stamp-based modification detection (#598, @katrinleinweber). auto_test_package() works correctly windows (#465). capture_output_lines() now exported (#504). compare.character() works correctly vectors length > 5 (#513, @brodieG) compare.default() gains max_diffs argument defaults printing first 9 differences (#538). compare.numeric() respects check.attributes() expect_equivalent() correctly ignores attributes numeric vectors (#485). Output expectations (expect_output(), expect_message(), expect_warning(), expect_silent()) invisibly return first argument consistent expectations (#615). expect_length() works object length method, just vectors (#564, @nealrichardson) expect_match() now accepts explicit perl fixed arguments, adapts failure message value fixed. also affects expectations forward expect_match(), like expect_output(), expect_message(), expect_warning(), expect_error(). expect_match() escapes special regular expression characters printing (#522, @jimhester). expect_message(), expect_warning() expect_error() produce clearer failure messages. find_test_scripts() looks \\.[rR] extension (#492, @brodieG) test_dir(), test_package(), test_check() unset R_TESTS env var (#603) test_examples() now works installed packages well source packages (@jimhester, #532). test_dir(), test_package(), test_check() gain stop_on_failure stop_on_waring arguments control whether error signalled tests fail generate warnings (#609, #619). test_file() now triggers gc() tests run. helps ensure finalisers run earlier (#535). test_path() now generates correct path called within tools::testInstalledPackage() (#542). test_path() longer assumes path exists (#448). test_that() calls without expectations generate default skip() (#413). test_dir() gains load_helpers argument (#505). show_failures() simply prints failure occurs. makes easier show failures examples. with_mock() disallows mocking functions base packages, doesn’t work current development version R (#553).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-102","dir":"Changelog","previous_headings":"","what":"testthat 1.0.2","title":"testthat 1.0.2","text":"CRAN release: 2016-04-23 Ensure std::logic_error() constructed std::string() argument, avoid build errors Solaris.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-101","dir":"Changelog","previous_headings":"","what":"testthat 1.0.1","title":"testthat 1.0.1","text":"CRAN release: 2016-04-21 New expect_output_file() compare output function text file, optionally update (#443, @krlmlr). Properly scoped use + compilation C++ unit testing code using Catch gcc clang , Catch includes code strictly conform C++98 standard. (2) Fixed --bounds memory access routing Catch output Rprintf(). (2) Ensure unit tests run R-oldrel (remove use dir.exists()). Improved overriding calls exit() within Catch, ensure compatibility GCC 6.0. (@krlmlr) Hardened formatting difference messages, previously presence % characters affect output (#446, @krlmlr). Fixed errors expect_equal() comparing numeric vectors without attributes (#453, @krlmlr). auto_test() auto_test_package() show results current test run previously failed runs (#456, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-100","dir":"Changelog","previous_headings":"","what":"testthat 1.0.0","title":"testthat 1.0.0","text":"CRAN release: 2016-04-14","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"breaking-changes-1-0-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"testthat 1.0.0","text":"expectation() function now expects expectation type (one “success”, “failure”, “error”, “skip”, “warning”) first argument. ’re creating expectations, ’ll need use expect() instead (#437).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-expectations-1-0-0","dir":"Changelog","previous_headings":"","what":"New expectations","title":"testthat 1.0.0","text":"expectation system got thorough overhaul (#217). primarily makes easier add new expectations future, also included thorough review documentation, ensuring related expectations documented together, evocative names. One useful change expectations invisibly return input object. makes possible chain together expectations magrittr: (make style even easier, testthat now re-exports pipe, #412). exception rule expectations evaluate (.e. messages, warnings, errors, output etc), invisibly return NULL. functions now consistent: using NA cause failure errors/warnings/messages/output (.e. ’re missing), NULL fail aren’t errors/warnings/messages/output. previously didn’t work expect_output() (#323), error messages confusing expect_error(..., NA) (#342, @nealrichardson + @krlmlr, #317). Another change expect_output() now requires explicitly print output want test print method: expect_output(\"\", \"\") fail, expect_output(print(\"\"), \"\") succeed. six new expectations: expect_type() checks type object (#316), expect_s3_class() tests object S3 given class, expect_s4_class() tests object S4 given class (#373). recommend using specific expectations instead general expect_is(). expect_length() checks object expected length. expect_success() expect_failure() new expectations designed specifically testing expectations (#368). number older features deprecated: expect_more_than() expect_less_than() deprecated. Please use expect_gt() expect_lt() instead. takes_less_than() deprecated. () deprecated. Please use explicit individual forms expect_error(..., NA) , expect_warning(.., NA) .","code":"factor(\"a\") %>% expect_type(\"integer\") %>% expect_s3_class(\"factor\") %>% expect_length(1)"},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"expectations-are-conditions-1-0-0","dir":"Changelog","previous_headings":"","what":"Expectations are conditions","title":"testthat 1.0.0","text":"Now expectations also conditions, R’s condition system used signal failures successes (#360, @krlmlr). known conditions (currently, “error”, “warning”, “message”, “failure”, “success”) converted expectations using new .expectation(). allows third-party test packages (assertthat, testit, ensurer, checkmate, assertive) seamlessly establish testthat compatibility issuing custom error conditions (e.g., structure(list(message = \"Error message\"), class = c(\"customError\", \"error\", \"condition\"))) implementing .expectation.customError(). assertthat package contains example.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"reporters-1-0-0","dir":"Changelog","previous_headings":"","what":"Reporters","title":"testthat 1.0.0","text":"reporters system class considerably refactored make existing reporters simpler make easier write new reporters. two main changes: Reporters classes now R6 classes instead Reference Classes. callbacks receive full context: add_results() passed context test well expectation. test_start() test_end() get context test. context_start() context_end() get context. Warnings now captured reported reporters. reporter output goes original standard output affected sink() expect_output() (#420, @krlmlr). default summary reporter lists warnings (#310), skipped tests (@krlmlr, #343). New option testthat.summary.max_reports limits number reports printed summary reporter. default 15 (@krlmlr, #354). MinimalReporter correct labels errors E failures F (#311). New FailReporter stop case failures errors tests (#308, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"other-1-0-0","dir":"Changelog","previous_headings":"","what":"Other","title":"testthat 1.0.0","text":"New functions capture_output(), capture_message(), capture_warnings() selectively capture function output. used expect_output(), expect_message() expect_warning() allow types output percolate (#410). try_again() allows retry code multiple times succeeds (#240). test_file(), test_check(), test_package() now attach testthat testing functions available. source_test_helpers() gets useful default path: testthat tests directory. defaults test_env() consistent source functions (#415). test_file() now loads helpers test directory running tests (#350). test_path() makes possible create paths files tests/testthat work interactively called tests (#345). Add skip_if_not() helper. Add skip_on_bioc() helper (@thomasp85). make_expectation() uses expect_equal(). setup_test_dir() removed. used previously, instead use source_test_helpers() find_test_scripts(). source_file() exports function testthat uses load files disk. test_that() returns logical indicates tests successful (#360, @krlmlr). find_reporter() (also high-level testing functions) support vector reporters. one reporter, MultiReporter created (#307, @krlmlr). with_reporter() used internally gains new argument start_end_reporter = TRUE (@krlmlr, 355). set_reporter() returns old reporter invisibly (#358, @krlmlr). Comparing integers non-numbers doesn’t raise errors anymore, falls back string comparison objects different lengths. Complex numbers compared using routine (#309, @krlmlr). compare.numeric() compare.character() received another overhaul. improve behaviour edge cases, provides strong foundation work. Added compare.POSIXt() better reporting datetime differences. expect_identical() is_identical_to() now use compare() detailed output differences (#319, @krlmlr). Added Catch v1.2.1 unit testing C++ code. See ?use_catch() details. (2)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-0110","dir":"Changelog","previous_headings":"","what":"testthat 0.11.0","title":"testthat 0.11.0","text":"CRAN release: 2015-10-14 Handle skipped tests TAP reporter (#262). New expect_silent() ensures code produces output, messages, warnings (#261). New expect_lt(), expect_lte(), expect_gt() expect_gte() comparison without equality (#305, @krlmlr). expect_output(), expect_message(), expect_warning(), expect_error() now accept NA second argument indicate output, messages, warnings, errors absent (#219). Praise gets diverse thanks praise package, ’ll now get random encouragement tests don’t pass. testthat longer muffles warning messages. don’t want see output, need explicitly quiet , use expectation captures (e.g. expect_warning()). (#254) Use tests inst/tests formally deprecated. Please move tests/testthat instead (#231). expect_match() now encodes match, well output, expectation message (#232). expect_is() gives better failure message testing multiple inheritance, e.g. expect_is(1:10, c(\"glm\", \"lm\")) (#293). Corrected argument order compare.numeric() (#294). comparison() constructure now checks arguments correct type length. bugs bug tests failed error like “values must length 1, FUN(X[[1]]) result length 2” (#279). Added skip_on_os(), skip tests specified operating systems (2). Skip test depends devtools installed (#247, @krlmlr) Added skip_on_appveyor() skip tests Appveyor (@lmullen). compare() shows detailed output differences character vectors different length (#274, @krlmlr). Detailed output expect_equal() doesn’t confuse expected actual values anymore (#274, @krlmlr).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-0100","dir":"Changelog","previous_headings":"","what":"testthat 0.10.0","title":"testthat 0.10.0","text":"CRAN release: 2015-05-22 Failure locations now formatted R error locations. Add ‘invert’ argument find_tests_scripts(). allows one select tests match pattern. (#239, @jimhester). Deprecated library_if_available() removed. test (test_dir(), test_file(), test_package(), test_check()) functions now return testthat_results object contains results, can printed converted data frame. test_dir(), test_package(), test_check() added ... argument allows filtering test files using, e.g., Perl-style regular expressions,fixed character filtering. Arguments ... passed grepl() (@leeper). test_check() uses new reporter specifically designed R CMD check. displays summary end tests, designed <13 lines long test failures R CMD check display something useful. hopefully stop BDR calling testthat “test obfuscation suite” (#201). compare() now documented exported. Added numeric method long numeric vectors don’t match ’ll see examples problem (#177). line spacing compare.character() tweaked. skip_if_not_installed() skips tests package isn’t installed (#192). expect_that(, equals(b)) style testing soft-deprecated. keep working, ’s longer demonstrated , new expectations available expect_equal(, b) style. (#172) , testthat suppresses messages warnings tests (#189) New test_examples() lets run package examples tests. example counts one expectation succeeds code runs without errors (#204). New succeed() expectation always succeeds. skip_on_travis() allows skip tests run Travis CI. (Thanks @mllg) colourise() removed. (Colour still supported, via crayon package.) Mocks can now access values local call with_mock (#193, @krlmlr). equality expectations now documented together (#173); matching expectations also documented together.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-091","dir":"Changelog","previous_headings":"","what":"testthat 0.9.1","title":"testthat 0.9.1","text":"CRAN release: 2014-10-01 Bump R version dependency","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-09","dir":"Changelog","previous_headings":"","what":"testthat 0.9","title":"testthat 0.9","text":"CRAN release: 2014-09-22","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-features-0-9","dir":"Changelog","previous_headings":"","what":"New features","title":"testthat 0.9","text":"BDD: testhat now comes initial behaviour driven development (BDD) interface. language similar RSpec Ruby Mocha JavaScript. BDD tests read like sentences, make easier understand specification function. See ?describe() information examples. ’s now possible skip() test informative message - useful tests available certain conditions, CRAN, internet connection available (#141). skip_on_cran() allows skip tests run CRAN. take advantage code, ’ll need either use devtools, run Sys.setenv(NOT_CRAN = \"true\")) Simple mocking: with_mock() makes easy temporarily replace functions defined packages. useful testing code relies functions slow, unintended side effects access resources may available testing (#159, @krlmlr). new expectation, expect_equal_to_reference() added. tests equality reference value stored file (#148, @jonclayden).","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-0-9","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 0.9","text":"auto_test_package() works , now uses devtools::load_all() higher fidelity loading (#138, #151). Bug compare.character() fixed, reported Georgi Boshnakov. colourise() now uses option testthat.use_colours (default: TRUE). FALSE, output colourised (#153, @mbojan). is_identical_to() calls .equal() generate informative error message two objects identical (#165). safe_digest() uses better strategy, returns NA directories (#138, #146). Random praise renabled default (!) (#164). Teamcity reporter now correctly escapes output messages (#150, @windelinckx). also uses nested suites include test names.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"deprecated-functions-0-9","dir":"Changelog","previous_headings":"","what":"Deprecated functions","title":"testthat 0.9","text":"library_if_available() deprecated.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-081","dir":"Changelog","previous_headings":"","what":"testthat 0.8.1","title":"testthat 0.8.1","text":"CRAN release: 2014-02-22 Better default environment test_check() test_package() allows S4 class creation tests compare.character() longer fails one value missing.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-08","dir":"Changelog","previous_headings":"","what":"testthat 0.8","title":"testthat 0.8","text":"CRAN release: 2014-02-20 testthat 0.8 comes new recommended structure storing tests. better meet CRAN recommended practices, testthat now recommend put tests tests/testthat, instead inst/tests (makes possible users choose whether install tests). new structure, ’ll need use test_check() instead test_packages() test file (usually tests/testthat.R) runs testthat unit tests. big improvement usability comes @kforner, contributed code allow default results (.e. produced SummaryReporter) include source references can see exactly failures occurred.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-reporters-0-8","dir":"Changelog","previous_headings":"","what":"New reporters","title":"testthat 0.8","text":"MultiReporter, combines several reporters one. (Thanks @kforner) ListReporter, captures test results file, context, test elapsed time. test_dir, test_file, test_package test_check now use ListReporter invisibly return summary tests data frame. (Thanks @kforner) TeamCityReporter produce output compatible TeamCity continuous integration environment. (Thanks @windelinckx) SilentReporter testthat can test calls test_that. (Thanks @craigcitro, #83)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"new-expectations-0-8","dir":"Changelog","previous_headings":"","what":"New expectations","title":"testthat 0.8","text":"expect_null() is_null check object NULL (#78) expect_named() has_names() check names vector (#79) expect_more_than(), is_more_than(), expect_less_than(), is_less_than() check values threshold. (#77, thanks @jknowles)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-0-8","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"testthat 0.8","text":"expect_that() (thus expect_* functions) now invisibly return expectation result, stops info label arguments length > 1 (thanks @kforner) fixed two bugs source_dir(): look source scripts right place, use chdir argument. using expect_equal() compare strings, default output failure provides lot information, hopefully help make finding string mismatches easier. SummaryReporter max_reports option limit number detailed failure reports show. (Thanks @crowding) Tracebacks now also contain information functions came (information available). matches expect_match now pass additional arguments grepl can use fixed = TRUE, perl = TRUE ignore.case = TRUE control details match. expect_match now correctly fails match NULL. (#100) expect_output, expect_message, expect_warning expect_error also pass … grepl, can use fixed = TRUE, perl = TRUE ignore.case = TRUE Removed stringr evaluate dependencies. () function makes possible negate tests. example, expect_that(f(), (throws_error())) asserts f() throw error. Make dir_state less race-y. (Thanks @craigcitro, #80) auto_test now pays attention ‘reporter’ argument (Thanks @crowding, #81) get_reporter(), set_reporter() with_reporter() now exported (#102)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-071","dir":"Changelog","previous_headings":"","what":"testthat 0.7.1","title":"testthat 0.7.1","text":"CRAN release: 2013-03-27 Ignore attributes is_true is_false (#49) make_expectation works types input (#52) Now works better evaluate 0.4.3. new fail() function always forces failure test. Suggested Richie Cotton (#47) Added TapReporter produce output compatible “test anything protocol”. Contributed Dan Keshet. Fixed auto_test identify wrong files changed. (Thanks Peter Meilstrup)","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-07","dir":"Changelog","previous_headings":"","what":"testthat 0.7","title":"testthat 0.7","text":"CRAN release: 2012-06-27 SummaryReporter: still return informative messages even tests defined (just bare expectations). (Fixes #31) Improvements reference classes (Thanks John Chambers) Bug fixes nothing generated gives_warning / shows_message. (Thanks Bernd Bischl) New make_expectation function programmatically generate equality expectation. (Fixes #24) SummaryReporter: don’t get praise tests. Depend methods rather requiring testthat works run Rscript auto_test now normalises paths enable better identification file changes, fixes bug instantiating new reporter object.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-06","dir":"Changelog","previous_headings":"","what":"testthat 0.6","title":"testthat 0.6","text":"CRAN release: 2011-12-30 mutatr classes replaced ReferenceClasses. Better documentation short-hand expectations. test_dir test_package gain new filter argument allows restrict tests run.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-05","dir":"Changelog","previous_headings":"","what":"testthat 0.5","title":"testthat 0.5","text":"CRAN release: 2011-06-01 bare expectations now correctly throw errors ","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-04","dir":"Changelog","previous_headings":"","what":"testthat 0.4","title":"testthat 0.4","text":"CRAN release: 2011-03-20 autotest correctly loads code executes tests environment contexts never closed opened, always closed end file fixed small bug test_dir test given environment expect_* short cut functions gain label argument, thanks Steve Lianoglou","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-03","dir":"Changelog","previous_headings":"","what":"testthat 0.3","title":"testthat 0.3","text":"CRAN release: 2010-08-31 expectations now shortcut form, instead expect_that(, is_identical_to(b)) can expect_identical(, b) new shows_message gives_warning expectations test warnings messages expect_that, equals, is_identical_to is_equivalent now additional label argument allows control appearance text used expected object (expect_that) actual object (functions) failure messages. useful loops run tests otherwise variable names identical, ’s difficult tell iteration caused failure. executing bare tests gives nicer output expectations now give information failure make easier track problem. test_file test_dir now run code separate environment avoid pollution global environment. also temporary change working directory tests can use relative paths. test_package makes easier run tests installed package. Code run manner access non-exported functions objects. errors failures occur, test_package throw error, making suitable use R CMD check.","code":""},{"path":"https://testthat.r-lib.org/dev/news/index.html","id":"testthat-02","dir":"Changelog","previous_headings":"","what":"testthat 0.2","title":"testthat 0.2","text":"CRAN release: 2010-07-25 colourise also works screen terminal equals expectation provides information failure expect_that extra info argument allow pass extra information ’d like included message - helpful ’re using loop run tests is_equivalent_to: new expectation tests equality ignoring attributes library_if_available now works! (thanks report fix Felix Andrews) specify larger width join pieces back together whenever deparse used (thanks report fix Felix Andrews) test_dir now looks files starting test (test- )","code":""}]