Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vignette on testing challenging functions #1265

Open
maelle opened this issue Dec 3, 2020 · 11 comments
Open

Vignette on testing challenging functions #1265

maelle opened this issue Dec 3, 2020 · 11 comments

Comments

@maelle
Copy link
Contributor

maelle commented Dec 3, 2020

At the moment the only reference to mockery is via the deprecation message of former mocking functions.

Could there be a link to mockery maybe from the README?

@hadley

This comment was marked as outdated.

@maelle

This comment was marked as outdated.

@hadley

This comment was marked as outdated.

@maelle
Copy link
Contributor Author

maelle commented Dec 3, 2020

https://blog.r-hub.io/2019/10/29/mocking/ was relatively popular (well for an R-hub post 🙂 ) so I think a vignette about such topics would be awesome.

@hadley hadley changed the title Add a prominent link to mockery? Vignetting on testing challenging functions Dec 4, 2020
@nbenn

This comment was marked as outdated.

@krlmlr

This comment was marked as outdated.

@maelle
Copy link
Contributor Author

maelle commented Jan 12, 2021

Regarding plots, some guidance on testthat visual snapshots vs vdiffr (or how the two tools complement each other) would be nice.

@hadley hadley changed the title Vignetting on testing challenging functions Vignette on testing challenging functions Sep 13, 2021
@hadley
Copy link
Member

hadley commented Jan 5, 2022

  • Use of expect_snapshot() for length-y text output
  • Plus use of mocking and/or transform to eliminate spurious differences

@hadley
Copy link
Member

hadley commented Sep 15, 2023

I made this list for a recent workshop on testing:

  • Output affected by RNG — withr::local_seed()
  • Output affected by other external state — withr::local_options() / withr::local_envvar()
  • Graphical output — https://vdiffr.r-lib.org/
  • Errors & other user facing text — snapshots
  • HTTP responses — httr2 mocking + httptest2
  • Interactivity — mocking

Are there any other major classes of challenge that you can think of?

@maelle
Copy link
Contributor Author

maelle commented Dec 19, 2023

Regarding interactivity (and other examples like "code that should be run if there is no internet connection"), maybe also mention escape hatches? https://blog.r-hub.io/2023/01/23/code-switch-escape-hatch-test/

@hadley
Copy link
Member

hadley commented Dec 19, 2023

@maelle in that case (especially with local_mocked_bindings()), mocking feels like a clear win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants