Testing Basic structure

  1. Turn your app into a package

  2. Create a test file for each function

  • If you have R/module.R
  • usethis::use_test() will create tests/testthat/test-module.R
  1. Create tests to check a individual properties of a function by defining one or more expect_ functions in test_that().
test_that("as.vector() strips names", {
  # ARRANGE (GIVEN)
  x <- c(a = 1, b = 2)
  
  # ACT (WHEN)
  x_unnamed <- as.vector(x)
  
  # ASSERT (THEN)
  expect_equal(x_unnamed, c(1, 2))
})