testing-r-packages

Develop R package tests using testthat 3+ with structured layouts and fixtures.

1|Updated Feb 17, 2026
One-click install
npx skills add https://github.com/JDenn0514/surveycore --skill testing-r-packages-jdenn0514
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-r-packages
Source: https://github.com/JDenn0514/surveycore/tree/main/.claude/skills/testing-r-packages
Command: npx skills add https://github.com/JDenn0514/surveycore --skill testing-r-packages-jdenn0514

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing robust R package tests can be tedious and inconsistent; this skill consolidates best practices for testthat 3+ to help developers create reliable, repeatable tests with structured layouts, fixtures, and mocking patterns.

Core Features & Use Cases

  • Standardized test structure aligned with testthat 3 edition, enabling clear separation between unit, integration, and snapshot tests.
  • Fixture and helper management including reusable data builders and static fixtures for reproducible results.
  • Mocking strategies with local_mocked_bindings and related utilities to isolate external dependencies in tests.
  • Snapshot testing guidance to validate complex outputs, messages, and warnings across changes.
  • Practical guidance for R package development workflows, CRAN checks, and continuous integration.

Quick Start

Install testthat 3 and initialize a testing directory with usethis, then begin creating tests under tests/testthat following the patterns described.

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 with testthat 3?

Structure R package tests with testthat 3 by organizing tests under tests/testthat, separating unit, integration, and snapshot tests, and using withr for cleanup to ensure self-contained, repeatable test execution.

What is the best way to mock external dependencies in R tests?

Mock external dependencies in R tests using local_mocked_bindings to isolate external calls, ensuring tests remain self-contained and produce reliable, reproducible results without requiring live API connections.

How does snapshot testing work in testthat for R packages?

Snapshot testing in testthat captures complex outputs, messages, and warnings into reference files, validating that changes across package updates do not unexpectedly alter the generated output structure.

Do I need testthat 3 to use fixtures and mocking in R package tests?

Yes, testthat 3 is required to use modern patterns like local_mocked_bindings and standardized fixture management, aligning your R package testing with current CRAN checks and continuous integration workflows.

Why should my R package tests use withr for cleanup?

Use withr for cleanup in R package tests to enforce self-contained test environments, automatically resetting global state and temporary modifications so tests remain isolated and reproducible.

When should I use static fixtures versus reusable data builders in R tests?

Use static fixtures for reproducible results with fixed data structures and reusable data builders for generating dynamic test inputs, maintaining clear separation between unit and integration test layers.