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 Sanofi-Public 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("Sanofi-Public/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')

Version

1.1.1

License

GPL (>= 2)

Maintainer

Edward Gillian

Last Published

March 2nd, 2026

Functions in test.assessr (1.1.1)

create_empty_covr_list

Create an empty covr list for fallback
create_test_reporter

Create Test Reporter
create_coverage_skip_stf

Run Coverage While Skipping Failing Tests
generate_test_pkg_summary

Generate Test Summary
create_test_skip_details

Generate Test Skip Details
get_biocgenerics_test_paths

Locate active test paths for Bioconductor RUnit layout
extract_short_path

Extract the Last Two Path Components from a File Path
get_function_no_tests

get functions with no tests
detach_pkg_if_attached

Detach a package if attached (internal)
create_results_summary

Create a Summary of Coverage Results
get_nstf_test_path

Collect All Applicable Nonstandard Test Paths for a Package (internal)
generate_coverage_section

Generate Coverage Section
create_long_summary_details

Generate Long Summary Details
load_test_helpers

Load Testthat Helper Files into Environment
find_project_root

Find R project root directory
map_test

Map the Structure of Expectations in a Testthat File
is_bioc_runit_layout

Detect if a package uses the Bioconductor RUnit layout
generate_test_report

Generate HTML Report for Package Test Assessment
set_up_pkg

Create Information on Local Package Installation
get_stf_test_path

Determine the appropriate standard test path for a package
generate_test_details

Generate Test Details
get_source_test_mapping_nstf

Map R Source Files to Corresponding Test Files
safe_value

Helper to conditionally apply handle_null or abbreviation
get_package_coverage

get package test coverage
get_pkg_name

Get Package Name for Display
fix_test_context

Ensure Test Results Have Valid Context Labels
map_tests_stf

Map the Structure of Testthat Tests (Standard Testing Framework)
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".
get_tests_skip_stf

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

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

Remove New Globals from Environment Based on Initial Snapshot
setup_covr_env

Setup coverage environment using an existing cov_env (CRAN-safe)
remove_run_unitTests_mapping

Remove mapping rows that point to run_unitTests.R
get_pkg_desc

Read Description file and parse the package name and version
get_tests_long_sum_stf

Summarize detailed testthat results
get_expect

Extract Expectation Calls from Parsed Testthat Code
get_test_metadata

Get test metadata
install_package_local

Install a Package from a Local Source Directory
nest_test

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

Initialise a temporary coverage environment (framework-aware)
nest_expect

Extract and Structure Expectations from Parsed Test Blocks
load_package_datasets

Load Datasets from a Package
unpack_tarball

Untar package and return installation directory
run_coverage

Run Coverage and Return Structured Coverage Results
load_dependencies_into_env

Load and Install Package Dependencies from a DESCRIPTION File
run_covr_modes

Run Coverage Analysis with Test Detection
load_package_into_env

Load package objects into a coverage environment
run_covr_skip_stf

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

Run covr in a Subprocess with a Timeout
run_covr_skip_nstf

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

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

Safely unload a package to avoid coverage conflicts
prepare_for_bioc_runit

Prepare a BioC/RUnit package for testing
safe_left_join

Safely perform a left join with error handling
unrowname

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

Check for Testing Infrastructure and Snapshot Files
compute_total_coverage

Compute approximate total coverage combining line coverage and test breadth
check_elements_simple

Check Which Elements Exist in a List
check_covr_skip_testit

Run testit Tests Individually and Capture Issues
check_covr_skip_Bioc_nstf

Check for skipped or errored test files (BiocGenerics)
check_covr_skip_nstf

Check for Skipped or Errored Test Files (non-testthat)
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_abbreviation

Convert number to abbreviation
cleanup_and_return_null

Clean up cov environment and return NULL
convert_number_to_percent

Convert number to percent
create_covr_list_no_skip

create covr_list when no tests are skipped
cov_env

Package-Private Coverage Environment
create_fail_reporter

Create Fail Reporter
create_file_coverage_df

Generate file coverage df