Dockerised R - Fail Build on Unit Test Fail


#1

Hi there,

I've got a Dockerised R app and would like to run testthat unit tests on it during the Docker build phase. If the tests fail, I want the build phase to fail too. I've tried to run the tests as so (I've written a test that purposely fails):

RUN R -e "setwd('/srv/shiny-server/testFrontend')" \
    -e "library(testthat)" \
    -e "test_dir(getwd(), reporter=SummaryReporter)"

But as you can see in the Docker build output, I get a successful build:

Step 6/8 : RUN R -e "setwd('/srv/shiny-server/testFrontend')"     -e "library(testthat)"     -e "test_dir(getwd(), reporter=SummaryReporter)" &&     sudo chmod -R 777 /srv/shiny-server/testFrontend
 ---> Running in 99acfb7b75d7
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
  Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> setwd('/srv/shiny-server/testFrontend')
> library(testthat)
> test_dir(getwd(), reporter=SummaryReporter)
testing the stuff: .1
══ Failed ══════════════════════════════════════════════════════════════════════
── 1. Failure: earthquakes contains expected names (@test_get_earthquakes.R#15) 
Names of `earthquakes` ('time', 'latitude', 'longitude', 'depth', 'mag', 'magType', 'nst', 'gap', 'dmin', 'rms', 'net', 'id', 'updated', 'place', 'type', 'horizontalError', 'depthError', 'magError', 'magNst', 'status', 'locationSource', 'magSource') don't match 'time', 'latitude', 'longitude', 'depth', 'mag', 'magType', 'nst', 'gap', 'dmin', 'rms', 'net', 'id', 'updated', 'place', 'type', 'horizontalError', 'depthError', 'magError', 'magNst', 'status', 'locationSource'
══ DONE ════════════════════════════════════════════════════════════════════════
> 
> 
Removing intermediate container 99acfb7b75d7
 ---> 1c7e06bd00fd
Step 7/8 : EXPOSE 3838
 ---> Running in 5cf5a750f64f
Removing intermediate container 5cf5a750f64f
 ---> 6b9fed73d449
Step 8/8 : CMD ["/usr/bin/shiny-server.sh"]
 ---> Running in b29f0add7b36
Removing intermediate container b29f0add7b36
 ---> 0eadad63264c
Successfully built 0eadad63264c

Not sure if this is the appropriate forum but it seems to be testthat not actually returning an error.

Many thanks,

Ciaran


#2

Well, for anyone interested - I solved this by using the stop_on_failure=TRUE flag as so:

test_dir(getwd(), stop_on_failure=TRUE)

#3

Yay! Glad it worked out.

If your question's been answered (even if by you!), would you mind choosing (your own answer) as a solution? (see FAQ below for how) It makes it a bit easier to visually navigate the site and see which questions still need help.

Thanks


#4

Literally did that as you sent it!


#5

Two ships in the night! :ship: