map_tests_stf: Map the Structure of Testthat Tests (Standard Testing...

View source: R/map_tests_stf.R

map_tests_stfR Documentation

Map the Structure of Testthat Tests (Standard Testing Framework)

Description

This function analyses the test directory used by the Standard Testing Framework (STF), typically 'tests/testthat/', and extracts a structured representation of the unit tests contained in the directory. It identifies test files, expectations, contexts, test names, and associated line ranges.

Usage

map_tests_stf(path = "tests/testthat")

Arguments

path

Character. Path to the test directory. Defaults to '"tests/testthat"'.

Details

The function scans all testthat test files matching the pattern 'test*.R'. For each file, it extracts structured metadata describing the hierarchy of expectations, including:

  • file name

  • context or description

  • test label

  • expectation type

  • line ranges associated with each expectation

Files that contain no parseable test structure are omitted. If no valid test files are found, the function returns 'NULL'.

Value

A consolidated 'data.frame' where each row corresponds to an expectation discovered within the STF test directory. The data frame typically contains:

file

Name of the test file in which the expectation appears.

test

The combined description and test label assigned to the expectation.

expectation

The expectation type detected (e.g., 'expect_equal').

linerange

The associated line numbers for that expectation.

This structured mapping is used by downstream STF processing functions to support skip mapping, coverage enhancement, and reporting.

See Also

list.files, lapply, rbind

Other stf_utility: create_coverage_skip_stf(), map_test(), nest_test(), run_covr_skip_stf()


test.assessr documentation built on March 3, 2026, 1:06 a.m.