π 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
rOpenSci guidance for package development.
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.
rOpenSci guidance for package development.
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.
Set up via usethis::use_testthat()
(once per package) and usethis::use_test()
(once per test file).
Formalize your random examples.
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!
applepie
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
π e.g.Β withr::local_options()
. Change then clean!tests/testthat/test-data
, locate it in tests via testthat::test_path("test-data")
.π‘ 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.
05:00