Skip to content

Feature request: add ability to include tests within the same file as the source code. Β #1993

@avhz

Description

@avhz

Bit of a long shot, but I was wondering if there would be any interest in adding the ability to include unit tests within the same file as the source code, instead of relying on tests/testthat for all tests (unit + integration).

Something along these lines:

## R/f1.R

f1 <- function() return(1:3)

testthat::expect_equal(f1(), c(1, 2, 3))
## R/f2.R

f2 <- function() return(letters[1:3])

testthat::expect_equal(f2(), c("a", "b", "c"))

This means tests/testthat could be reserved for integration tests, and unit tests are "closer" to the code.

The closest I can get to this is to just have assertions within documentation.

We would somehow need to hide the tests from being run when the package is built, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions