tdd-workflow

Enforce test-driven development for R projects using testthat workflows.

189|26|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/ab604/claude-code-r-skills --skill tdd-workflow-ab604
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tdd-workflow
Source: https://github.com/ab604/claude-code-r-skills/tree/main/.claude/skills/tdd-workflow
Command: npx skills add https://github.com/ab604/claude-code-r-skills --skill tdd-workflow-ab604

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides a guided, reproducible workflow to implement test-driven development in R projects, ensuring code is validated by tests before features are added, bug fixes, or refactoring.

Core Features & Use Cases

  • Establish a testthat-based workflow to create unit and integration tests early.
  • Enforce minimum test coverage targets (e.g., 80%) and encourage best practices for robust R packages and Shiny apps.
  • Include ready-made steps to initialize testing infrastructure, create tests, and organize test files, with guidance for iterative development.
  • Use cases: starting a new feature, fixing a bug, or refactoring existing code in R packages, data pipelines, or Shiny apps, to ensure quality.

Quick Start

  • Run: usethis::use_testthat(3) to initialize testthat edition 3
  • Create tests: usethis::use_test("function_name") and usethis::use_r("function_name")
  • Write tests following the three-level hierarchy: File → Test → Expectation
  • Keep coverage above 80% and add edge-case tests

Frequently Asked Questions about tdd-workflow

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

FAQPage Schema
How do I set up test-driven development for an R package using testthat?

Test-driven development for R packages begins by initializing testthat edition 3 with usethis::use_testthat(3), then creating paired test and source files using usethis::use_test() and usethis::use_r() to enforce a structured testing workflow.

Can I use this TDD workflow for Shiny apps and data pipelines, or is it only for R packages?

Yes, this TDD workflow applies to Shiny apps, data pipelines, and R packages. It provides scaffolding to establish unit and integration tests across these environments, ensuring reliable code during feature development, bug fixing, and refactoring.

What is the recommended test coverage target when implementing TDD in R?

The recommended test coverage target for R projects using this workflow is 80% or higher. Maintaining this threshold ensures robust code validation and encourages the inclusion of edge-case tests during iterative development.

How do I structure integration tests and unit tests in R without creating a messy workflow?

Structure R tests using the three-level hierarchy: File, Test, and Expectation. This testthat-based workflow organizes unit and integration tests logically, providing ready-made steps to initialize infrastructure and maintain clean test files.

Do I need to install extra dependencies to start writing R tests with this TDD workflow?

No extra dependencies are required. This TDD workflow relies on standard CRAN tooling, specifically the usethis and testthat packages, to establish testing infrastructure, create tests, and organize files with minimal setup.

Why does my R code break during refactoring and how can TDD prevent it?

R code breaks during refactoring when unvalidated changes introduce errors. TDD prevents this by enforcing a test-driven workflow where testthat validates existing behavior before changes are made, ensuring reliable and well-tested code.