tests/README.md

colocboost unit-testing

Overview

This repository contains a comprehensive testing framework for the colocboost R package. The framework is designed to ensure the reliability and correctness of package functionality through automated testing.

Quick Start

  1. Our unit testing setup is managed by pixi. Please follow the instructions at https://pixi.sh/latest/#installation if you have not already installed pixi.

  2. In the root of this repository, run the helper script to create a pixi.toml file. This file is deliberately ignored in .gitignore because it is ephemeral and will be regenerated whenever CI is run.

    bash .github/workflows/create_toml_from_yaml.sh $(pwd)

  3. Run all tests with a pixi task: bash pixi run devtools_test or test one file using pixi run: bash pixi run R -e 'devtools::test_active_file("tests/testthat/test_colocboost.R")'

Files and Structure

Adding New Tests

When adding new functionality to the colocboost package, corresponding tests should be added to maintain test coverage. Follow these steps:

  1. Identify which test file should contain the new tests, or create a new test file if necessary
  2. Write test functions using the testthat package's expectations
  3. Run the tests to ensure they pass

Example test:

test_that("new_function produces expected output", {
  # Arrange
  input_data <- prepare_test_data()

  # Act
  result <- new_function(input_data)

  # Assert
  expect_equal(result$some_value, expected_value)
  expect_true(is.data.frame(result$data))
})

Test Coverage

The covr package is used to measure test coverage, which indicates what percentage of the code is being tested.

To generate a test coverage report:

pixi run codecov

GitHub Actions Workflow

This testing framework includes GitHub Actions workflows that automatically run the tests on every pull request. The workflows test the package on Linux and macOS to ensure cross-platform compatibility.

The workflow is defined in .github/workflows/ci.yaml and automatically runs: - R CMD check - Test coverage reporting with codecov.io

Test results and coverage statistics are available on the GitHub Actions page after each pull request.

For more information, check the testthat documentation.



Try the colocboost package in your browser

Any scripts or data that you put into this service are public.

colocboost documentation built on June 8, 2025, 11:07 a.m.