|
| 1 | +--- |
| 2 | +name: unit-test-project-conformant |
| 3 | +description: Guides the agent to write unit tests that strictly conform to the project's existing testing structure, patterns, and style by learning from similar tests before writing anything new. |
| 4 | +--- |
| 5 | +# Unit Test (Project-Conformant) Skill |
| 6 | + |
| 7 | +This skill ensures the agent does **not invent test structure** and instead learns how the project already tests similar code, then writes the new test in the same style, location, and pattern. |
| 8 | + |
| 9 | +The goal is for the new test to be **indistinguishable from existing tests**. |
| 10 | + |
| 11 | +## When to Use |
| 12 | + |
| 13 | +- Use this skill every time a unit test must be written or modified. |
| 14 | +- Use this skill when adding coverage for new functions, classes, or behavior. |
| 15 | +- Use this skill when refactoring code that requires corresponding test updates. |
| 16 | +- This skill is required whenever the agent is tempted to create a “clean” or “ideal” test structure. |
| 17 | + |
| 18 | +## Instructions |
| 19 | + |
| 20 | +### Step 1 — Discover How the project Tests Similar Code |
| 21 | + |
| 22 | +Before writing any test: |
| 23 | + |
| 24 | +- Identify the file, function, or class to be tested. |
| 25 | +- Search the project for tests covering: |
| 26 | + - The same module |
| 27 | + - The same directory |
| 28 | + - Similar functions |
| 29 | + - Similar classes |
| 30 | + - Similar behavior |
| 31 | +- Use search terms such as: |
| 32 | + - Function name |
| 33 | + - Class name |
| 34 | + - Module name |
| 35 | + - Error messages |
| 36 | + - Public API names |
| 37 | + |
| 38 | +You must examine **at least 2–3 similar tests** before proceeding. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +### Step 2 — Extract the Test Pattern |
| 43 | + |
| 44 | +From the discovered tests, learn: |
| 45 | + |
| 46 | +- Where tests are located |
| 47 | +- File naming conventions |
| 48 | +- Test naming conventions |
| 49 | +- Whether tests are: |
| 50 | + - Standalone functions |
| 51 | + - Inside classes |
| 52 | + - Parametrized |
| 53 | + - Fixture-driven |
| 54 | + - Integration-style |
| 55 | +- Assertion style |
| 56 | +- Mocking style |
| 57 | +- Helper utilities used |
| 58 | +- What is intentionally *not* tested |
| 59 | + |
| 60 | +You are learning the project’s **testing contract**. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +### Step 3 — Decide Where the Test Belongs |
| 65 | + |
| 66 | +Follow existing structure exactly: |
| 67 | + |
| 68 | +- If similar code is tested in a shared file → add to that file |
| 69 | +- If similar code is tested inside a class → add a method there |
| 70 | +- If similar tests extend parametrization → extend it |
| 71 | +- If similar behavior is only tested indirectly → do the same |
| 72 | + |
| 73 | +Do **not** create a new test file unless similar tests do. |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### Step 4 — Match Style Exactly |
| 78 | + |
| 79 | +Mirror the project’s style for: |
| 80 | + |
| 81 | +- Function and variable names |
| 82 | +- Imports |
| 83 | +- Assertion style |
| 84 | +- Fixtures |
| 85 | +- Mocking |
| 86 | +- Test utilities |
| 87 | +- Formatting and layout |
| 88 | + |
| 89 | +Do not introduce new libraries, helpers, or patterns. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +### Step 5 — Respect How the project Chooses to Test |
| 94 | + |
| 95 | +If similar methods: |
| 96 | + |
| 97 | +- Are tested indirectly |
| 98 | +- Are tested via integration tests |
| 99 | +- Are not given standalone unit tests |
| 100 | + |
| 101 | +Then you must follow the same pattern. |
| 102 | + |
| 103 | +Do **not** create standalone unit tests if the project does not. |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +### Step 6 — Match the Level of Coverage |
| 108 | + |
| 109 | +Match the project’s expectations: |
| 110 | + |
| 111 | +- If tests check only success paths → do the same |
| 112 | +- If tests include edge cases → include them |
| 113 | +- If tests include error cases → include them |
| 114 | +- If tests use heavy mocking → do the same |
| 115 | +- If tests avoid mocking → avoid it |
| 116 | + |
| 117 | +Do not over-test compared to existing patterns. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +### Step 7 — Reuse Existing Helpers and Fixtures |
| 122 | + |
| 123 | +Search for and reuse: |
| 124 | + |
| 125 | +- Fixtures |
| 126 | +- Base test classes |
| 127 | +- Utilities |
| 128 | +- Custom assertions |
| 129 | +- Shared setup logic |
| 130 | + |
| 131 | +Do not recreate logic that already exists. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +### Step 8 — Write the Test Last |
| 136 | + |
| 137 | +Only after completing all discovery steps should you write the test. |
| 138 | + |
| 139 | +The result should look like it was written by the same author as the surrounding tests. |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## Anti-Patterns (Never Do These) |
| 144 | + |
| 145 | +- Creating new test structure because it seems “better” |
| 146 | +- Writing standalone tests when the project does not |
| 147 | +- Introducing new testing frameworks |
| 148 | +- Adding excessive assertions not seen elsewhere |
| 149 | +- Adding mocks where the project avoids them |
| 150 | +- Guessing where tests belong without searching |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +## Final Checklist |
| 155 | + |
| 156 | +Before finishing, confirm: |
| 157 | + |
| 158 | +- Test is in the correct location |
| 159 | +- Naming matches existing tests |
| 160 | +- Structure matches existing tests |
| 161 | +- Assertions match existing tests |
| 162 | +- Fixtures/helpers are reused |
| 163 | +- No new patterns introduced |
| 164 | +- Coverage level matches similar tests |
| 165 | + |
| 166 | +--- |
| 167 | + |
| 168 | +Use the ask questions tool if you need to clarify requirements with the user. |
0 commit comments