一键导入
tdd-workflow
Test-driven development workflow for qcthat. Use when writing any R code (writing new features, fixing bugs, refactoring, or reviewing tests).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Test-driven development workflow for qcthat. Use when writing any R code (writing new features, fixing bugs, refactoring, or reviewing tests).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | tdd-workflow |
| description | Test-driven development workflow for qcthat. Use when writing any R code (writing new features, fixing bugs, refactoring, or reviewing tests). |
Write a failing test first, then implement the minimal code to make it pass, then refactor. Never write implementation code without a failing test driving it.
Tests for R/{FunctionName}.R go in tests/testthat/test-{FunctionName}.R.
Place new tests next to similar existing ones.
# Full suite
devtools::test(reporter = "check")
# Single file
devtools::test(filter = "FunctionName", reporter = "check")
Testing functions load code automatically. You do not need to call library() or devtools::load_all() separately.
Goal: 100% for every edited file. After editing R/FunctionName.R, verify:
covr_res <- devtools:::test_coverage_active_file("R/FunctionName.R")
which(purrr::map_int(covr_res, "value") == 0)
Files excluded from the coverage requirement:
R/qcthat-package.RR/aaa-shared.RTest individual functions in isolation:
test_that("FetchRepoIssues() returns a qcthat_Issues tibble (#2)", {
result <- FetchRepoIssues()
expect_s3_class(result, "qcthat_Issues")
})
For complex outputs that are hard to specify with equality assertions:
test_that("print method is stable (#123)", {
expect_snapshot(print(CompileTestResults(test_results_object)))
})
# For errors, wrap expect_error() inside expect_snapshot() so both the error
# class and the message text are captured in the snapshot:
test_that("errors on invalid input (#456)", {
expect_snapshot({
(expect_error(
FetchRepoIssues(strOwner = 123),
class = "qcthat-error"
))
})
})
When snapshots change intentionally:
testthat::snapshot_review("test_name")
testthat::snapshot_accept("test_name")
Snapshots are stored in tests/testthat/_snaps/.
desc of every new test_that() call
should end with a parenthetical issue reference:
test_that("FetchRepoIssues() returns correct columns (#1)", { ... })
test_that("errors on empty input (#noissue)", { ... })
# Deprecated → Modern
context("Data validation") # Remove — filename serves this purpose
expect_equivalent(x, y) # expect_equal(x, y, ignore_attr = TRUE)
with_mock(...) # local_mocked_bindings(...)
expect_is(x, "data.frame") # expect_s3_class(x, "data.frame")
expect_equal(x, y) # with numeric tolerance
expect_equal(x, y, tolerance = 0.001)
expect_equal(x, y, ignore_attr = TRUE)
expect_identical(x, y) # exact match
expect_error(code)
expect_error(code, "pattern")
expect_error(code, class = "qcthat-error")
expect_error(code, class = "qcthat-error-bad_input")
expect_warning(code)
expect_no_warning(code)
expect_message(code)
expect_no_message(code)
expect_setequal(x, y) # same elements, any order
expect_in(element, set)
expect_named(x, c("a", "b"))
expect_type(x, "double")
expect_s3_class(x, "qcthat_Issues")
expect_length(x, 10)
expect_true(x)
expect_false(x)
expect_null(x)
withr patterns for temporary statewithr::local_options(list(qcthat.option = TRUE))
withr::local_envvar(MY_VAR = "value")
withr::local_tempfile(lines = c("a", "b"))
Store static test data in tests/testthat/fixtures/ and access via:
test_path("fixtures", "sample.rds")
local_mocked_bindings(
ExternalFn = function(...) "mocked_result"
)
result <- MyFunctionThatCallsExternalFn()
Creates GitHub issues for the package repository. Use when asked to create, file, or open a GitHub issue, or when planning new features or functions that need to be tracked.
Document package functions. Use when asked to document functions.
Implements a GitHub issue end-to-end. Use when asked to implement, work on, or fix a specific issue number.
Guide for writing R code in qcthat. Use when writing new functions, designing APIs, or reviewing/modifying existing R code.
Identify likely GitHub issues connected to test cases. Use when asked to tag tests with issues or get started with qcthat.
Search and rewrite R source code by syntax using astgrepr. Use when asked to find patterns in code, search for function calls, identify usage of specific arguments, locate structural patterns across R files, or perform find-and-replace on code structure.