Title: | 'testthat' Unit Test Enhancements |
---|---|
Description: | Enhance package 'testthat' by allowing tests to be attached to the function/object they test. This allows to keep functional and unit test code together. |
Authors: | Claudia Beleites [aut, cre], Erick Oduniyi [aut] |
Maintainer: | Claudia Beleites <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2025-02-14 05:11:54 UTC |
Source: | https://github.com/cran/hySpc.testthat |
The returned function can be executed. If that is done within a testthat::Reporter, the results will be reported accordingly. Without reporter, the test runs silently if successful and stops if it fails.
get_test(object)
get_test(object)
object |
to which the test is attached |
the test (function)
f <- function(x) x^2 test(f) <- function() { context("f") test_that("correct result for complex number", { expect_equal(f(1i), -1 + 0i) }) } get_test(f) library(testthat) ## execute the test get_test(f)() with_reporter("summary", get_test(f)())
f <- function(x) x^2 test(f) <- function() { context("f") test_that("correct result for complex number", { expect_equal(f(1i), -1 + 0i) }) } get_test(f) library(testthat) ## execute the test get_test(f)() with_reporter("summary", get_test(f)())
Execute test attached to a function with testthat::Reporter.
test_fun(object, reporter = "minimal")
test_fun(object, reporter = "minimal")
object |
to which the test is attached |
reporter |
testthat::Reporter to use |
the test (function)
f <- function(x) x^2 test(f) <- function() { context("f") test_that("correct result for complex number", { expect_equal(f(1i), -1 + 0i) }) } test_fun(f)
f <- function(x) x^2 test(f) <- function() { context("f") test_that("correct result for complex number", { expect_equal(f(1i), -1 + 0i) }) } test_fun(f)
This function attaches unit tests in value
to an object (typically a
function) as an attribute "test"
.
test(f) <- value
test(f) <- value
f |
the function (object) to which the tests are to be attached |
value |
the test code, a function with no parameters |
f
with the test attached as attribute "test"
f <- function(x) x^2 test(f) <- function() { context("f") test_that("correct result for complex number", { expect_equal(f(1i), -1 + 0i) }) }
f <- function(x) x^2 test(f) <- function() { context("f") test_that("correct result for complex number", { expect_equal(f(1i), -1 + 0i) }) }
If testthat::testthat-package is available, run the unit tests and display the results.
unittest(ns, standalone = TRUE, reporter = "progress")
unittest(ns, standalone = TRUE, reporter = "progress")
ns |
namespace (package) to test |
standalone |
if |
reporter |
testthat::Reporter to be used. |
Invisibly returns a data.frame with the test results
Claudia Beleites
unittest("hySpc.testthat")
unittest("hySpc.testthat")