agentleFS
Muriel-SalvanMuriel-Salvan/x_aeon_agents/skills/applying-test-conventions/SKILL.md

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.

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
  1. Distinctive:

    Always tell the user "SKILL: I am applying test conventions" to inform the user that you are running this skill.

    line 12
  2. Distinctive:

    Always respect this structure for a test scenario:

    line 20
  3. Distinctive:

    Always call only the public interface of the class to be tested.

    line 22
  4. Distinctive:

    Write simple expectations and assertions on results of the public interface of the class to be tested.

    line 23
  5. Distinctive:

    Use test helpers to make sure each step takes very few lines in each scenario.

    line 24
  6. Distinctive:

    Only relying on public methods to run and assert guarantees freedom to refactor the internals of the classes being tested, without …

    line 57
  7. Distinctive:

    If this is not the case, understand what could break the isolation of those unit tests and fix it.

    line 62
  8. Very specific:

    Always use it every time another skill specifically mentions skill: applying-test-conventions.

    line 104
  9. Distinctive:

    Always use it every time the user asks you to write or modify tests.

    line 105
  10. Distinctive:

    Always use it every time you need to write or modify tests.

    line 106

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. Setup test data and mocks. Use defaults to only express test data relevant to the test scenario at hand.
  2. Always call only the public interface of the class to be tested. Never call private methods of the interface.
  3. 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
end

Example: 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
end

Rationale

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'
end

Example: 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'
end

Rationale

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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.