Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
ᴅʀ. ᴍᴏᴡɪɴᴄᴋᴇʟ'ꜱ
ᴅʀ. ᴍᴏᴡɪɴᴄᴋᴇʟ'ꜱ
@Drmowinckels@fosstodon.org  ·  activity timestamp last month

Day 15: Snapshot Testing with testthat

Test complex outputs that are hard to specify exactly.

Text snapshots:
test_that("error messages are informative", {
expect_snapshot(my_function(bad_input), error = TRUE)
})

Pro Tip: Review snapshot changes carefully - they capture everything, including whitespace and formatting.

#rstats #RPackageAdvent2025

2 media
test_that("plots look right", {
  p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
  vdiffr::expect_doppelganger("mtcars-scatter", p)
})
test_that("plots look right", { p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() vdiffr::expect_doppelganger("mtcars-scatter", p) })
test_that("plots look right", { p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() vdiffr::expect_doppelganger("mtcars-scatter", p) })
test_that("error messages are informative", {
  expect_snapshot(my_function(bad_input), error = TRUE)
})
test_that("error messages are informative", { expect_snapshot(my_function(bad_input), error = TRUE) })
test_that("error messages are informative", { expect_snapshot(my_function(bad_input), error = TRUE) })
  • Copy link
  • Flag this post
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1-beta.35 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct