Best practices for writing R package tests with testthat version 3+. Use this skill when writing or organizing tests for an R package or when improving existing tests that use testthat. It covers test structure and expectations, self-sufficient test design, proper cleanup with withr, fixtures, mocking external dependencies, snapshot testing, and BDD-style describe/it patterns.
Install
npx skills add posit-dev/skills --skill r-testthatnpx skills add posit-dev/skills --skill r-testthat -a claude-code -gnpx skills add posit-dev/skills --skill r-testthat -a codex -ggemini skills install https://github.com/posit-dev/skills.git --path r-lib/r-testthatgh skill install posit-dev/skills r-testthatgit clone --depth 1 https://github.com/posit-dev/skills /tmp/posit-dev__skills
mkdir -p ~/.claude/skills ~/.agents/skills
cp -R /tmp/posit-dev__skills/r-lib/r-testthat ~/.claude/skills/r-testthat # Claude Code
cp -R /tmp/posit-dev__skills/r-lib/r-testthat ~/.agents/skills/r-testthat # Codex, Cursor, Gemini CLI, Copilot, OpenCode