$ whoami Colin FAY Data Scientist & R-Hacker at ThinkR, a french company focused on Data Science & R. Hyperactive open source developer, lead developer of the {golem} project. https://thinkr.fr https://rtask.thinkr.fr https://twitter.com/_colinfay https://github.com/colinfay https://colinfay.me Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 2 / 41
Data Science engineering, focused on R. Training Software Engineering R in production Consulting ThinkR Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 4 / 41
Today's menu A (non-comprehensive) overview of testing technologies in the R world Program Testing in R, why? Testing R packages Benchmark and loadtest Disclaimer I know nothing about AI Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 6 / 41
R CMD check devtools::check() rcmdcheck::rcmdcheck() Command line interface & can be used on CI/CD Testing R packages Package infrastructure comes with native testing Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 17 / 41
{testthat} test_that("The meaning of life is 42", { expect_equal( meaning_of_life(), 42 ) }) Testing R packages Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 18 / 41
Testing R packages Other tools to define tests for functions {testit}, which comes with two functions (assert() and test_pkg()) {testthis}, to enhance unit testing (use_testdata(), test_coverage()) {tinytest}, a lightweight and dependency free unit testing framework Complementary tools {webmockr} and {vcr}, to test for HTTP requests {httptest}: webtesting through {httr} Document {covr} & {covrpage}, to document test coverage {testdown}: {testthat} results as a bookdown Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 21 / 41
CI/CD Travis https://docs.travis-ci.com/user/languages/r/ Set up R specific dependencies, and test the package language: r before_install: - tlmgr install index install: - R -e 'devtools::install_deps(dep = T)' script: - R CMD build . - R CMD check *tar.gz Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 23 / 41
CI/CD GitLab Some docker images can be used as a base: image: colinfay/r-ci-tidyverse:3.6.0 test: script: - R -e 'remotes::install_local()' - R -e 'devtools::check()' Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 24 / 41
{shiny} specific {shinytests} Test visual regression of your application puppeteer Command line tool to mock a web session, in NodeJS {crrry} R tool to drive a {shiny} session Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 25 / 41
Benchmark and load Timing with {bench} res <- bench::mark( plus = 1+1, sum = sum(1, 1), iterations = 10000 ) res # A tibble: 2 x 6 expression min median `itr/sec` mem_alloc `gc/sec`
1 plus 71ns 101ns 4561272. 0B 0 2 sum 222ns 266ns 1733893. 0B 0 Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 31 / 41
Benchmark and load in {shiny} {shinyloadtest} : native R package + Cli to record and replay load tests {dockerstats} : get Docker stats inside R {crrry} + {dockerstats} : replay session and watch the Docker stats Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 33 / 41
Wrapper around docker stats Turns the stats from Docker into an R dataframe Can be called recursively Focus - {dockerstats} Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 34 / 41
To conclude Test often, test soon Everything can, and should be scripted Testing is not just about functions, it's also about load and speed R Packages make our life easier Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 38 / 41