testthat

Create and organize testthat unit tests for R packages.

1|1|Updated Mar 26, 2024
One-click install
npx skills add https://github.com/j-welling/NEPSroutines --skill testthat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testthat
Source: https://github.com/j-welling/NEPSroutines/tree/main/.claude/skills/testthat
Command: npx skills add https://github.com/j-welling/NEPSroutines --skill testthat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing, evaluating, reviewing, and debugging R package tests with testthat to ensure code correctness and maintainability.

Core Features & Use Cases

  • Structured test organization under tests/testthat with test- and helper-files for repeatable validation.
  • Clear, readable expectations using test_that and a suite of expectation helpers to verify behavior.
  • Practical scenarios include validating package functions, checking edge cases, and integrating with CI/test coverage discussions.

Quick Start

Create tests under tests/testthat and run devtools::test() to execute them.

Frequently Asked Questions about testthat

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure unit tests for an R package using testthat?

Structure unit tests for an R package by placing files under tests/testthat using test-*.R for validation and helper-*.R for shared setup. This organization standardizes repeatable validation workflows and ensures code maintainability.

How do I run testthat tests and verify package function behavior?

Run testthat tests by executing devtools::test() in your R environment. This command evaluates your expectations and verifies package function behavior, checking edge cases and confirming code correctness during development.

Does testthat work with CI pipelines for R packages?

Yes, testthat integrates with CI pipelines for R packages. It supports common usage patterns and integration scenarios, allowing continuous validation of code correctness and automated debugging during development workflows.

What is the best way to debug failing expectations in R testthat?

The best way to debug failing expectations in R testthat is to use structured test_that blocks with readable expectation helpers. This isolates failures during debugging sessions by verifying specific code behaviors and edge cases clearly.

Can I use helper files for shared setup when writing R unit tests?

Yes, you can use helper-*.R files for shared setup when writing R unit tests. Placing them in the tests/testthat directory ensures repeatable validation by standardizing prerequisite data and environments across multiple test files.