mardi 8 janvier 2019

Running suite of R testthat tests that are not in a separate file

I ran into a problem where I want to run multiple tests with testing values set as parameters. I want to use R's testthat package because I think it is very convenient framework. The problem is when I define my suite as a function and run it, it will stop execution on first broken assertion whereas I want my testing suite to run all tests and produce some sort of report at the end (similar as testthat::test_file()). Please consider following example:

RunTest<- function(mean1, mean2){
    test_that("Testing mean of Sepal length", {
        expect_lte(mean(iris$Sepal.Length), mean1)
    })
    test_that("Testing mean of Petal.Length", {
        expect_lte(mean(iris$Petal.Length), mean2)
    })
}

When I run RunTest(4,5) it will break on the first assertion and will not proceed to the second. I was thinking about wrapping every test with silent try/catch but it feels that there should be a better way around this.

Aucun commentaire:

Enregistrer un commentaire