agentleFS
kagent-devkagent-dev/kagent/.agents/skills/given-when-assert-that/SKILL.md

given-when-assert-that

Skill4.2k starsChanged 5 days agoApache-2.0View on GitHub

Design and write Go behavior tests as readable Given/When/AssertThat scenarios with observable assertions, using ordinary Go tests without a BDD framework.

Adopted by

Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data

Week of Sep 13: 0 new projectsWeek of Sep 20: 0 new projectsWeek of Sep 27: 0 new projectsWeek of Oct 4: 0 new projectsWeek of Oct 11: 0 new projectsWeek of Oct 18: 0 new projectsWeek of Oct 25: 0 new projectsWeek of Nov 1: 0 new projects
Sep 2026Oct 2026Nov 2026
New projects taking a version of this file each week, over the 8 weeks our latest run read: only 0 in all, so this is a hint, not a trend.

Who's talking about kagent-dev/kagent

The biggest 5 of 52 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 52

Talked about on GitHub, Hacker News and Bluesky (52 times).

On GitHub · 50

45 more on GitHub

On Hacker News · 1

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use this skill when writing Go behavior tests, including tests for new features and bug fixes.

    line 8
  2. Distinctive:

    Use an eventive When, not a stative one.

    line 19
  3. Very specific:

    Keep variants in a scenarios matrix when they share an action and assertion.

    line 21
  4. Distinctive:

    Keep setup local for a single case.

    line 25
  5. Distinctive:

    If updating an existing test, preserve its behavior, assertions, cleanup, and meaningful edge cases.

    line 40

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

Given/When/AssertThat Go tests

Use this skill when writing Go behavior tests, including tests for new features and bug fixes. Keep the tests executable with go test. Do not add a BDD runner, .feature files, code generation, or a generic step registry.

Choose behavior before writing test code

  • Identify the user-visible contract and the boundary that proves it: an HTTP or gRPC response, handler reachability, caller identity, persisted state, or emitted event. Do not test only a helper when the behavior depends on listener wiring, serialization, or persistence.
  • Start with a working case and the few failure or boundary cases that could change the outcome. Include missing, empty, malformed, and fallback inputs only when the contract treats them differently. Set up any state that a negative assertion depends on, so the test cannot pass against an empty or unwired system.
  • For each case, write down Given <relevant state>, when <one action>, assert that <observable outcome>. Make the assertion specific enough to fail if the behavior is absent; avoid tests that just check constants, mocks, or implementation steps.

Write the scenario as an ordinary Go test

  • Give each test function a short behavior name. When subtests help distinguish cases, give each t.Run a sentence: Given <precondition>, when <one action with its input variant>, assert that <observable outcome>. Do not add a subtest or fixture just to satisfy the naming pattern.
  • Use an eventive When, not a stative one. "When a caller sends an RPC without a token" names the stimulus. "When an RPC has no credentials" describes state. Put stable state in Given.
  • Make the name match the actual input. "No valid token" includes missing, malformed, and expired tokens. Do not use it for a case that sends only a missing token.
  • Keep variants in a scenarios matrix when they share an action and assertion. Give distinct behaviors separate named subtests. Do not branch assertions on expected outcomes to force unlike cases into one table.

Keep the invocation readable

Keep setup local for a single case. When several cases share substantial setup or transport mechanics, put test functions and scenario matrices above reusable helpers and create a fresh fixture inside each subtest unless shared state is immutable and the cases cannot interfere.

func TestProtectedEndpoint(t *testing.T) {
	t.Run("Given a protected endpoint, when a request has no token, assert that dispatch is rejected", func(t *testing.T) {
		newAuthFixture(t).
			GivenProtectedEndpoint().
			WhenRequestWithoutCredentials().
			AssertThatRequestIsRejectedBeforeDispatch()
	})
}

Given sets up the invariant, When performs the action, and AssertThat checks the result at the boundary. Keep an existing Options-based fixture setup when it makes configuration choices explicit; do not flatten it into raw transport calls for presentation. Pair this rejection case with a valid-token case proving the handler is reachable; otherwise a permanently unwired handler could pass the negative test. Use stage methods only when they remove repeated mechanics.

If updating an existing test, preserve its behavior, assertions, cleanup, and meaningful edge cases. Do not rewrite neighboring tests merely for presentation.

Check that the tests prove the contract

Run gofmt on changed Go files and the smallest go test command that exercises every new case. Run the repository's applicable lint command. For a regression test, confirm it fails against the broken behavior and passes with the fix; for a new feature, confirm each assertion observes the intended boundary rather than a fixture's own return value. Replace / in dynamic names so testing.T.Run does not split a sentence into nested subtests.

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.