Light Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

dgkf/testex

Repository files navigation

testex test examples

Add tests and assertions in-line in examples

Quick Start

Set up your package to use testex using

testex::use_testex()

and then start adding tests!

#' Hello, World!
#'
#' @examples
#' hello("World")
#' @test "Hello, World!"
#'
#' hello("darkness my old friend")
#' @test grepl("darkness", .)
#'
#' @export
hello <- function(who) {
paste0("Hello, ", who, "!")
}

If you were already using testthat, you'll immediately see a new test context for testing your examples. And if you aren't using testthat, then you'll find that your tests are being run with your examples when you run R CMD check

roxygen2 tags

@test

will check that the result of the last example is identical to your test. You can use the example output in a function using a ..

#' @examples
#' sum(1:10)
#' @test 55
#' @test is.numeric(.)

@testthat

is similar, but has the added benefit of automatically inserting a . into testthat::expect_* functions.

#' @examples
#' sum(1:10)
#' @testthat expect_equal(55)
#' @testthat expect_vector(numeric())

Prior Art

  • roxytest A slightly different approach. Allows tests to be written in-line, but generates test files used directly by a testing framework.

About

Add tests and assertions in-line in R package examples

Topics

Resources

Readme

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Contributors