testing-r-packages

Write and organize R package tests with testthat 3.

466|38|Updated Nov 21, 2025
One-click install
npx skills add https://github.com/posit-dev/skills --skill testing-r-packages
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-r-packages
Source: https://github.com/posit-dev/skills/tree/main/r-lib/testing-r-packages
Command: npx skills add https://github.com/posit-dev/skills --skill testing-r-packages

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps R developers adopt robust, maintainable testing practices for R packages by using testthat 3. It provides a clear blueprint for structuring tests, leveraging fixtures, snapshots, and mocking, while promoting consistent expectations and reliable results.

Core Features & Use Cases

  • Test organization and patterns for testthat 3 (describe/it and test_that) to create readable, navigable suites.
  • Fixtures, snapshot testing, and mocking strategies, with guidance on cleanup using withr for deterministic tests.
  • Guidance on building CI-ready tests and scalable test suites that cover typical edge cases in package development.

Quick Start

Create a basic testthat 3 suite in your package and start writing describe/it or test_that blocks to cover core functions.

Frequently Asked Questions about testing-r-packages

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

FAQPage Schema
How do I structure R package tests using testthat 3?

Ensure deterministic R package tests by using withr-based cleanup for side effects and fixtures, which provides reliable results by automatically resetting global state after each test execution.

What is the best way to mock functions and use snapshots in testthat?

Mock functions and use snapshot testing in testthat to capture and compare complex outputs against known reference values, isolating external dependencies while verifying package behavior remains stable.

Does testthat 3 edition support describe/it blocks and snapshot testing?

Yes, testthat 3 edition supports describe/it blocks and snapshot testing, enabling developers to build CI-ready and scalable test suites that cover typical edge cases in package development workflows.

Why use fixtures and withr for deterministic R package testing?

Use fixtures and withr for deterministic R package testing to manage setup, teardown, and cleanup of side effects, ensuring tests remain self-contained and produce consistent reliable results.