I am looking for the best practice with brilliant testthat . Where is the best place to place your library(xyzpackage) calls to take full advantage of the package?
At first I set up runtest.R path and package settings. Then I run test_files(test-code.R) , where it only contains context and tests. Example for structure:
# runtests.R library(testthat) library(data.table) source("code/plotdata-fun.R") mytestreport <- test_file("code/test-plotdata.R")
and in my test files, for example. test-plotdata.R (stripped down version):
#my tests for plotdata context("Plot Chart") test_that("Inputs valid", { test.dt = data.table(px = c(1,2,3), py = c(1,4,9)) test.notdt <- c(1,2,3)
Is this the way that @hadley was meant to be used? From the article articles are not clear. Should I also duplicate library calls in my test files? Do you need a library configured in each context or only one at the beginning of the file?
Is it possible to convince a library (package) in r?
To use test_dir() and other functions , what is the best way to configure your files . I use require () in my functions, but I also set up sample test data in contexts. (In the example above, you will see that I will need the data.table package for test.dt for use in other tests).
Thank you for your help.
source share