Get access to all lessons in this course.
-
Setup packages
- devtools and usethis
- Package names and authors
- Choose a license
- Setup git + GitHub
-
Write code
- Writing functions
- Adding functions to our package
- Using other packages
- Packages so good they get their own functions
- Organizing .R files
-
Document
- roxygen2: In-Line Documentation for R
- Argument descriptions and examples
- Helper functions
- Joining documentation
-
Test
- Unit tests for R
- Organizing tests
- R CMD Check
- Types of Test Files
- Test Coverage
-
Teach
- Examples
- README
- Spellcheck
-
Add data and files
- Store data and files
- Include data for tests and create RMarkdown templates
- Create other templates
- Launch and store Shiny apps
- Citations, ignoring files, and including add-ins
Package Development with R
Unit tests for R
This lesson is locked
This lesson is called Unit tests for R, part of the Package Development with R course. This lesson is called Unit tests for R, part of the Package Development with R course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
For this section of the course, you’ll need the materials in this GitHub repo. You can download or clone them. After you download or clone the materials from the GitHub repo for this section of the course, open the entire project by clicking 04_avalanchr.Rproj.
Your Turn
Working in the exercises.Rmd file:
Use use_test() to create a new file. Call it “resident_connection”
Change the test description (the first argument of test_that()) to “connection is returning valid data”
In the test_that() function, remove the default expectations. Replace them with this code
Re-load your package.
Press the “Run tests” button in RStudio (above the script pane) or run test_file(“tests/testthat/test-resident_connection.R”) in the console.
Learn More
To learn about the testthat
package, check out its website.
The R Packages book has a good chapter on testing.
Shannon Pileggi has also written a blog post called Getting started with unit testing in R.
You need to be signed-in to comment on this post. Login.