GET better at testing your package!

πŸ‘‹ Bonjour !

Code of Conduct

Code of Conduct including how to make reports.

Recording

I’ll be recording from now.

You can turn your camera off and change your display name if you want.

Why test your package?

Why test your package?

Why test your package?

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.

Why test your package?

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.

How to test?

Now what?

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.

Now what?

Today we will explore less cute tests. πŸ‘»

HTTP things are hard to test

  • Slow tests?
  • Overburdening the web resource?
  • Using credits for testing?
  • Impossible to trigger errors?

Good use case for learning more about testing techniques! πŸŽ‰

Our goals today

Gaining specific knowledge about HTTP testing via vcr, general knowledge about testing R packages with testthat!

Website tour

πŸ”— https://http-testing-r.netlify.app/

Get to know applepie

Client for R-universe API. πŸš€

Jeroen Ooms’ keynote talk.

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! πŸŽ‰

Demo

πŸ“¦ Load, use, check our (cute?) little package.

πŸ₯ Add a cute little test to it.

β˜‚οΈ Explore its test coverage.

πŸš₯ Set up continuous integration.

Demo πŸš€

Back from the demo

A package with two functions, non zero test coverage, continuous integration… πŸ’

But what if our internet connection gets fragile? 😱

Test fixtures

“A test fixture is an environment used to consistently test some item, device, or piece of software.”

Wikipedia via testthat “test fixtures” vignette.

Text fixtures in general in R

  • Put example data you put in tests/testthat/test-data, locate it in tests via testthat::test_path("test-data").

What about fixtures for HTTP testing?

πŸ’‘ 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!

Demo πŸš€

Back from the demo

Now our package has a test that can work when internet is down.

Time for a break! β˜•

05:00