# Automated testing with 'testthat' in practice

### Abstract

You test your code. We know you do. How else are you sure that your changes don’t break the program? But after you commit, you discard those pesky scripts and throw away code. Don’t you think it’s a bit of a waste to dump all that effort that took you quite a decent chunk of your day to conjure? Well, here you are, so let’s see another way. A better way.

In the words of Hadley Wickham, author of the testthat package, “It’s not that we don’t test our code, it’s that we don’t store our tests so they can be re-run automatically.”

In this tutorial we are going to see how to accomplish this using automated unit testing, leveraging the testthat package. We’ll cover (pun intended) how much of your code went untested, with the covr package, and also we’ll learn to test functions independently of their dependencies, making use of mock functions.

We’ll also introduce Test-driven Development, or TDD.

Date
Event
Location
Room 18.0.A09. Campus de Getafe, Calle Madrid, 126, 28903 Getafe, Madrid, Spain.

### Requirements

R/RStudio + testthat and covr packages.