applying-test-conventions
Skill2 starsChanged 2 months agoBSD-3-ClauseView on GitHub
Applies idiomatic test conventions, structure, and best practices when writing or modifying unit tests. What this does is defining a set of rules to follow when dealing with any test file. Use this when the user is asking to create, edit, refactor, or review test files or when the project contains test scenarios. Use this skill also in Plan mode.
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- addressing-pull-request-commentsSkill
- analyzing-github-issueSkill
- applying-ruby-conventionsSkill
- committing-changesSkill
- creating-pull-requestSkill
- editing-filesSkill
- enforcing-project-rulesSkill
- implementing-github-issueSkill
- improving-agent-reflectionSkill
- running-cli-in-wsl-portableSkill
- syncing-branch-with-baseSkill
- updating-docSkill
- validating-production-qualitySkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 9 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Always tell the user "SKILL: I am applying test conventions" to inform the user that you are running this skill.
- Distinctive: line 20
Always respect this structure for a test scenario:
- Distinctive: line 22
Always call only the public interface of the class to be tested.
- Distinctive: line 23
Write simple expectations and assertions on results of the public interface of the class to be tested.
- Distinctive: line 24
Use test helpers to make sure each step takes very few lines in each scenario.
- Distinctive: line 57
Only relying on public methods to run and assert guarantees freedom to refactor the internals of the classes being tested, without …
- Distinctive: line 62
If this is not the case, understand what could break the isolation of those unit tests and fix it.
- Very specific: line 104
Always use it every time another skill specifically mentions skill: applying-test-conventions.
- Distinctive: line 105
Always use it every time the user asks you to write or modify tests.
- Distinctive: line 106
Always use it every time you need to write or modify tests.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Applying test conventions
Inform the user
- Always tell the user "SKILL: I am applying test conventions" to inform the user that you are running this skill.
Conventions to be followed when testing
Those conventions use examples using Ruby, but are applicable to any programming language and test framework.
Rule: Always write concise scenarios with a 3-steps structure: setup, run and expect
Always respect this structure for a test scenario:
- Setup test data and mocks. Use defaults to only express test data relevant to the test scenario at hand.
- Always call only the public interface of the class to be tested. Never call private methods of the interface.
- Write simple expectations and assertions on results of the public interface of the class to be tested. Never assert results from private methods or internal states of the interface. Use test helpers to make sure each step takes very few lines in each scenario.
Example: Incorrect
it 'counts comments' do
collection = MyCollection.new([
{ author: 'test_author1', comment: 'test_comment1' },
{ author: 'test_author1', comment: 'test_comment2' },
{ author: 'test_author2', comment: 'test_comment3' }
])
comments = collection.instance_variable_get(:@items)
expect(comments.size).to eq 3
endExample: Correct
# Helper providing test comments
def comment_factory(author: 'test_author', comment: 'test_comment')
{ author:, comment: }
end
it 'counts comments' do
collection = MyCollection.new(3.times.map { comment_factory })
expect(collection.nbr_elements).to eq 3
endRationale
Concise unit tests that have a clear structure are much easier to read and maintain. Only relying on public methods to run and assert guarantees freedom to refactor the internals of the classes being tested, without impacting unit tests.
Rule: Make sure each test scenario runs in an isolated way
Running scenarios in whatever order or group should never change the result of the test suite run. If this is not the case, understand what could break the isolation of those unit tests and fix it.
Example: Incorrect
it 'overrides the app default path from the environment' do
ENV['OVERRIDE_APP_PATH'] = 'overridden_app/'
expect(log_file()).to eq ['overridden_app/log.txt']
end
it 'logs actions' do
app_run
# The following expect fails with the suite, but passes when run solo.
expect(File.read('default_app/log.txt')).to include 'Action has been run'
endExample: Correct
it 'overrides the app default path from the environment' do
original_value = ENV['OVERRIDE_APP_PATH']
ENV['OVERRIDE_APP_PATH'] = 'overridden_app/'
begin
expect(log_file()).to eq ['overridden_app/log.txt']
ensure
ENV['OVERRIDE_APP_PATH'] = original_value
end
end
it 'logs actions' do
FileUtils.rm_f 'default_app/log.txt'
app_run
expect(File.read('default_app/log.txt')).to include 'Action has been run'
endRationale
Unit tests should have deterministic behaviour, whether they are run alone or grouped with other tests.
When to use it
- This skill can be used when in Plan mode.
- Always use it every time another skill specifically mentions
skill: applying-test-conventions. - Always use it every time the user asks you to write or modify tests.
- Always use it every time you need to write or modify tests.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

