👋 Bonjour !
Code of Conduct including how to make reports.
I’ll be recording from now.
You can turn your camera off and change your display name if you want.
wow who knew there was actually a robust way to test functions besides trying random examples and seeing if they work and then not remembering them once you clear your console— Sharla Gelfand (@sharlagelfand) January 15, 2019
If you use software that lacks automated tests, you are the tests.— Jenny Bryan (@JennyBryan) September 22, 2018
All packages should have a test suite that covers major functionality of the package. The tests should also cover the behavior of the package in case of errors.
It is good practice to write unit tests for all functions, and all package code in general, ensuring key functionality is covered. Test coverage below 75% will likely require additional tests or explanation before being sent for review.
Testing is often demonstrated with cute little tests and functions where all the inputs and expected results can be inlined. But in real packages, things aren’t always so simple
Jenny Bryan in a testthat vignette.
Today we will explore less cute tests. 👻
Good use case for learning more about testing techniques! 🎉
Gaining specific knowledge about HTTP testing via vcr, general knowledge about testing R packages with testthat!
Client for R-universe API. 🚀
R-universe is a new platform by rOpenSci for publishing and discovering R packages, Rmd articles, and other R based content.
And it has an API! 🎉
📦 Load, use, check our (cute?) little package.
🐥 Add a cute little test to it.
☂️ Explore its test coverage.
🚥 Set up continuous integration.
A package with two functions, non zero test coverage, continuous integration… 💐
But what if our internet connection gets fragile? 😱
“A test fixture is an environment used to consistently test some item, device, or piece of software.”
withr::local_options(). Change then clean!
tests/testthat/test-data, locate it in tests via
💡 How about we create a test fixture with stored or faked API responses?
This is the idea behind vcr and httptest. (webfakes is a bit different).
Let’s try vcr!
Now our package has a test that can work when internet is down.