simonpcouch/side/write-unit-tests
Claude Code and agent skill by simonpcouch/side
- community
Checking that the SKILL.md file is still in the repository.
Write minimal, concise testthat 3e unit tests for R package code
Install
npx vskill@latest install simonpcouch/side/write-unit-testsSKILL.md
Unit testing
Write minimal, concise testthat 3e unit tests for R package code. Given the contents of an R file, prefixed with the header "## Contents", and a selection that is a subset of those contents, prefixed with the header "## Selection", reply with a testthat unit test tests the functionality in the selection. Respond with only the testing code, no code comments and no backticks or newlines around the response, though feel free to intersperse newlines within the function call as needed, per tidy style.
For example, consider the following selection:
In that case, return the following tests:
In this case, we:
- Set the value of an envvar temporarily with a
withr::local_*()function. Another common temporary test fixtures might be temporary options withwithr::local_options().
- Use
expect_true()andexpect_false()to test boolean outcomes.
- Use
expect_equal()to test that a function call returns an expected value.
- Use
expect_snapshot()witherror = TRUEto test for an error message. Whenever you see erroring code withstop(),stopifnot(),rlang::abort(), orcli::cli_abort(), test it with a snapshot witherror = TRUE.
The last example tested an error with expect_snapshot(error = TRUE). If you see another condition, like a warning or message, test it with expect_snapshot() but assign the results to an intermediate value. For example, if your selection is:
Test it with:
To test conditional paths that are hard to get into, use mocking with testthat::local_mocked_bindings(). For example, provided the selection:
You might write:
Some functions will have a check_*() function in their signature—in that case, do not test the functionality of the checking function unless the definition of the function is part of the selection. For example, provided:
Return:
You will need to determine the number of test_that() blocks to use to test a given function thoughtfully. Balance these principles:
- In general, the fewer
test_that()blocks to test a given function, the better. local*()settings and mocks should not have to be "reset" within atest_that()call.- Function "successes" should be tested in a different block than failures. If you're specifically snapshotting messages/warnings/errors, those tests should live in a different
test_that()block than the usual, "happy" control flow tests.
So, in the above, since there were two distinct local_mocked_bindings() calls needed, there were two distinct test_that() calls.
However, if the selection also includes the definition of the check_*() function, test it independently. If you had been provided:
You would also return the following tests:
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckinginst/skills/write-unit-tests/SKILL.md
Popularity
- Repository stars
- 47
- Repository forks
- 4
- 7-day trend score
- 19
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/simonpcouch/side/write-unit-tests)