r-lib-testing

Validate R packages using testthat 3 patterns and structured test organization.

1|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/nq-rdl/agent-extensions --skill r-lib-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: r-lib-testing
Source: https://github.com/nq-rdl/agent-extensions/tree/main/skills/r-lib-testing
Command: npx skills add https://github.com/nq-rdl/agent-extensions --skill r-lib-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Standardizes how R packages are tested by providing clear conventions, tooling guidance, and modern testthat patterns.

Core Features & Use Cases

  • Test organization patterns: file structure, describe/it style, and traditional test_that usage.
  • Fixtures, snapshots, and mocking: guidance on creating reusable fixtures and using mock bindings.
  • Workflow guidance: setup, running tests, and best practices for reliable test suites.

Quick Start

Install testthat 3, initialize tests with usethis::use_testthat(3), and start adding tests under tests/testthat.

Frequently Asked Questions about r-lib-testing

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

FAQPage Schema
How do I set up testthat for R package testing?

To set up testthat for R package testing, install testthat 3 and initialize the test suite by running usethis::use_testthat(3). This configures the required tests/testthat directory structure and edition for your package.

What is the best way to organize R unit tests using testthat?

The best way to organize R unit tests is using structured testthat patterns. You can group assertions using the describe/it style for readability or apply traditional test_that blocks within files under the tests/testthat directory.

How do I use mocking and fixtures in testthat?

Mocking and fixtures in testthat isolate code by replacing dependencies with mock bindings and reusable test data. This provides structured guidance on creating fixtures and employing mocks for reliable, isolated testing workflows.

When should I use snapshot testing in R packages?

You should use snapshot testing in R packages to capture and compare complex object outputs over time. Snapshot testing records expected output, making it easier to detect unintended changes and manage regression testing across package updates.

Does this R testing guidance require testthat 3 edition?

Yes, this R testing guidance requires testthat 3 edition. It standardizes modern R package testing by providing conventions, tooling guidance, and best practices specifically designed for the features and capabilities of testthat 3.

What are the limitations of traditional test_that usage compared to describe blocks?

Traditional test_that usage groups multiple expectations into a single block, which can obscure specific failures. The describe/it style provides more granular, readable test organization, while traditional usage remains suitable for simpler, isolated assertion workflows.