Learn R Programming

test.assessr

Overview

test.assessr helps in the assessment of a package's test reliability and validity.

It calculates unit test coverage for packages with standard testing frameworks and non-standard testing frameworks, including Bioconductor packages.

Description

This package executes the following tasks:

  1. upload the source package(tar.gz file)

  2. Unpack the tar.gz file

  3. Install the package locally

  4. Run code coverage

Package Installation

from Github

  • Create a Personal Access Token (PAT) on github

    • Log into your github account
    • Go to the token settings URL using the Token Settings URL
      • (do not forget to add the SSH GitHub authorization)
  • Create a .Renviron file with your GITHUBTOKEN as:

# .Renviron
GITHUBTOKEN=dfdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxfdf
  • restart R session
  • You can install the package with:
auth_token = Sys.getenv("GITHUBTOKEN")
devtools::install_github("pharmaverse/test.assessr", ref = "main", auth_token = auth_token)

Usage

Assessing your own package for test coverage

To assess your package's test coverage, do the following steps:

1 - save your package as a tar.gz file

  • This can be done in RStudio -> Build Tab -> More -> Build Source Package

2 - Run the following code sample by loading or add path parameter to your tar.gz package source code

# for local tar.gz R package
dp <- (path/to/your/package)

test_package_coverage <- get_package_coverage(dp)

generate_test_report(test_package_coverage)

test.assessr results

For a package with a standard testing framework such as testthat or testit or non-standard testing frameworks such as BiocGenerics and RUnit, test_assessr can provide data on which tests are passing and which tests are skipped.

The standard testing framework test report tells you which tests have passed:

The report provides information on which test blocks have passed and the start line of each test block.

The standard testing framework test report tells you which tests have been skipped:

The report provides information on which test blocks have passed, expectation type, and the start line of each test block.

The non-standard testing framework test report tells you which functions have no tests:

The report tells you which tests have passed:

The test report tells you which tests have been skipped:

Current/Future directions

  • to develop methods for checking the validity of test data
  • to develop methods of checking mocks

Acknowledgements

The project is inspired by the covrpage and mpn.scorecard packages and draws on some of their ideas and functions.

Copy Link

Version

Install

install.packages('test.assessr')

Monthly Downloads

521

Version

2.1.2

License

GPL (>= 2)

Maintainer

Edward Gillian

Last Published

June 10th, 2026

Functions in test.assessr (2.1.2)

create_test_reporter

Create Test Reporter
create_results_summary

Create a Summary of Coverage Results
dt_find_wrapper_tests

Locate data.table wrapper test scripts (internal)
extract_short_path

Helper to extract "R/<file>" from any path by taking the last two components
generate_test_details

Generate Test Details
get_expect

Extract Expectation Calls from Parsed Testthat Code
create_tinytest_coverage

Create coverage from tinytest under covr instrumentation (internal)
generate_test_pkg_summary

Generate Test Summary
create_test_skip_details

Generate Test Skip Details
create_long_summary_details

Generate Long Summary Details
dt_compute_untested_functions

Compute untested functions from coverage using srcref spans (internal)
detect_frameworks

Detect which test frameworks are present in a package
detach_pkg_if_attached

Detach a package if attached (internal)
generate_coverage_sections

Generate Coverage Sections (multi-framework)
generate_coverage_section

Generate Coverage Section (single framework)
get_pkg_name

get package name for display
get_source_test_mapping_bioc_nstf

Map Bioconductor source files to test files, avoiding false positives. Tightens filename and content-based matching; handles short names like "t".
generate_test_report

Generate HTML Report for Package Test Assessment
get_package_coverage

get package test coverage
get_function_no_tests

get functions with no tests
get_pkg_desc

Read Description file and parse the package name and version
get_stf_test_path

Determine the appropriate standard test path for a package
get_nstf_test_path

Collect all applicable nonstandard test paths for a package (internal)
get_test_framework_type

Get human-readable test framework type label
get_runit_test_paths

Locate active test paths for Bioconductor RUnit layout
get_source_test_mapping_nstf

Map R Source Files to Corresponding Test Files
find_project_root

Find R project root directory
get_biocgenerics_test_paths

Locate active test paths for Bioconductor RUnit layout
fix_test_context

Fix Missing Test Contexts
handle_null

Helper function to replace NULL with "N/A"
is_runit_layout

Detect if a package uses RUnit layout (BioC or RUnit-only)
get_tests_skip_stf

Safely generate skip test mapping from problem tests and test map
is_bioc_runit_layout

Detect if a package uses the Bioconductor RUnit layout
initialise_covr_env

Initialise a temporary coverage environment (framework-aware)
get_tests_long_sum_stf

Summarize detailed testthat results
get_test_metadata

Get test metadata
install_package_local

Install a Package from a Local Source Directory
map_tests_stf

Map the Structure of Testthat Tests (Standard Testing Framework)
load_base_r_packages_into_env

Load Base R packages into an isolated coverage environment
load_package_into_env

Load package objects into a coverage environment
prepare_for_bioc_runit

Prepare a BioC/RUnit package for testing Detaches common BioC infrastructure packages (if attached) and load_all() the target package before RUnit tests. Also clears R_TESTS to avoid interference from the check harness.
load_dependencies_into_env

Load and Install Package Dependencies from a DESCRIPTION File
map_test

Map the Structure of Expectations in a Testthat File
load_test_helpers

Load Testthat Helper Files into Environment
normalize_test_results

Normalize test results for single or multi-framework structure
remove_run_unitTests_mapping

Remove mapping rows that point to run_unitTests.R
load_package_exports_into_env

Load exported objects from installed packages into an environment
nest_expect

Extract and Structure Expectations from Parsed Test Blocks
load_package_datasets

Load Datasets from a Package
nest_test

Group Parsed Testthat Code into Logical Test Blocks (Internal)
run_covr_modes

Run Coverage Analysis with Test Detection
restrict_test_paths_to_framework

Restrict a list of test paths to a single framework
run_covr_skip_dt_nstf

Run Coverage Analysis on data.table Package Source and Tests
run_covr_skip_bioc_nstf

Run coverage with skip detection for Bioconductor RUnit-based packages
run_covr_skip_nstf

Run Coverage Analysis on Package Source and Non‑Standard Tests (NSTF)
run_coverage

Run Coverage and Return Structured Coverage Results
run_covr

Run covr in a Subprocess with a Timeout
prepare_tests_for_package_dt

Prepare package-specific test environment for data.table (internal)
set_up_pkg

Create Information on Local Package Installation
run_one_framework

Run coverage for a single test framework
remove_new_globals

Remove New Globals from Environment Based on Initial Snapshot
run_covr_skip_runit_nstf

Run coverage with skip detection for RUnit and Bioconductor RUnit-based packages
unpack_tarball

Untar package and return installation directory
safe_unload_package

Safely unload a package to avoid coverage conflicts
safe_value

Helper to conditionally apply handle_null or abbreviation
setup_covr_env

Set up a coverage environment for isolated test execution
unrowname

Add Identifier Column and Remove Row Names from a Data Frame
safe_left_join

Safely perform a left join with error handling
run_covr_skip_stf

Run Coverage with Skipped Failing Tests (Standard Testing Framework)
check_covr_skip_bioc_nstf

Check for skipped or errored test files (BiocGenerics)
create_fail_reporter

Create Fail Reporter
check_covr_skip_nstf

Check for skipped or errored test files (non-testit)
cleanup_and_return_null

Clean up cov environment and return NULL
create_covr_list_no_skip

create covr_list when no tests are skipped
check_covr_skip_testit

Run testit tests individually, capturing all warnings and errors, with dynamic package root detection
compute_total_coverage

Compute approximate total coverage combining line coverage and test breadth
check_covr_skip_runit_nstf

Check for skipped or errored test files (BiocGenerics)
create_base_tests_coverage

Create coverage by running base-style tests under covr (internal)
check_pkg_tests_and_snaps

Check for tests/testthat and _snaps folder and count golden tests
compute_multi_framework_total

Compute aggregate total coverage across multiple frameworks
create_nstf_covr_list

Create the NSTF Coverage List
convert_number_to_abbreviation

Convert number to abbreviation
check_elements_simple

Check Which Elements Exist in a List
create_file_coverage_df

Generate file coverage df
compute_test_files_clean_dt

Compute wrapper data.table test files to run for coverage (internal)
create_coverage_skip_stf

Run Coverage While Skipping Failing Tests
convert_vectors_to_df

This internal function takes named character vectors (e.g., `tests_skipped`, `tests_passing`) from a list and converts them into data frames for easier reporting or processing.
convert_number_to_percent

Convert number to percent
cov_env

Package-Private Coverage Environment
create_empty_covr_list

Create an empty covr list for fallback