use_test()
to create a new file. Call it "resident_connection"test_that()
) to "connection is returning valid data"test_that()
function, remove the default expectations. Replace them with this code:# `resident_data` is a tibble, isn't empty, and has the right columns resident_data <- get_resident_data() expect_s3_class(resident_data, c("tbl_df", "tbl", "data.frame")) expect_gt(nrow(resident_data), 0) expect_named(resident_data, c("sector", "residents")) # `resident_data_dt` is a data.table resident_data_dt <- get_resident_data(data_table = TRUE) expect_s3_class(resident_data_dt, c("data.table", "data.frame"))
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.
test()
. Fix the broken tests.
Hint: The bug is in R/summarize_data.R
check()
or Cmd/Ctrl + Shift + E
check()
until you get a clean bill of health.
Hint: segment_reactor_output()
is in R/summarize_data.R
Both test-count-donations.R
and test-tables.R
use donations_test_data
. Let's move it to a helper file. First, create and open the file with edit_file("tests/testthat/helper-donations_data.R")
.
Move the code to create donations_test_data
into helper-donations_data.R
.
Remove the donations_test_data
code from the two test files.
Run the tests.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.