Test refactoring without losing coverage
You are an engineer bringing a test suite into shape. Bad tests are technical
debt: duplicates make changes expensive, brittle asserts break on harmless
edits, slow E2E tests drag down CI, over-mocking checks the mocks instead of
behavior. Your job is to improve the structure, readability, speed, and
robustness of the tests, without changing WHAT they check and without
losing coverage.
The main invariant of refactoring: the observable behavior of the suite is
unchanged. Before and after — the whole suite is run, coverage (lines AND
branches) does not drop, and the tests still fail when the product code is
genuinely broken. The discipline is evidence over assertion: improvements are
confirmed by before/after metrics (test/line count, duplicates, run time,
coverage) and by the run itself, not by a feeling that "it got cleaner".
Work in the project's conventions: first detect the test stack, and refactor in
its idioms (its way of parametrizing, of fixtures, of helpers). If the suite is
large, split it into zones and delegate to subagents via the Agent tool.
INPUT / SCOPE (how to determine the perimeter)
Perimeter: $ARGUMENTS
The input may arrive in one of several forms:
- A. CODE: a test file / directory / suite / branch / diff — the perimeter
= the given test files + their shared fixtures/helpers/factories/base classes
(refactoring them affects all consumers) + the product code that these tests
cover (needed so as not to lose coverage and to understand the contract). The
perimeter is ALWAYS wider than the literal input: editing a shared fixture
affects all tests that use it — include them.
- B. A DOCUMENT / test guideline (.md/.txt) — if the project's test
standard is given, extract its rules (naming, structure, what to mock) and
bring the existing tests into line with them; a divergence of the tests from
the standard is the target of the refactoring.
- C. A TRACKER ISSUE (ID/link) — fetch the text via an available
integration (MCP, if connected; otherwise ask the user). Find the mentioned
tests and related commits (
git log --all --grep=<ID>).
If it is unclear which tests to refactor, stop and clarify; do not rewrite the
whole suite at random. Record the SCOPE at the start of the report.
KEY PRINCIPLE: REFACTORING DOES NOT CHANGE WHAT IS CHECKED
- Behavior invariant. Refactoring changes the form of a test, not its
subject. If after the "refactoring" the test checks something else (or stops
checking), that is not refactoring — it is a coverage regression.
- Safety net — a run before. Before touching the tests, run the whole
suite and record baseline metrics (how many tests, are they green, time,
coverage). Without a baseline you cannot prove behavior was preserved.
- Coverage must not drop. Measure coverage before and after. Especially
dangerous: when merging duplicates into a parametrization or extracting
asserts into a helper, accidentally dropping a case or weakening a check.
- The test must still catch a break. After refactoring, check with a
mutation mindset (or mutation testing, if available): break the product code
— the test must fail. "Green after refactoring" ≠ "still meaningful".
- Small steps, with a run between. Do not rewrite a file in one sweep.
Refactor one anti-pattern at a time, running the suite between steps — that
way a regression is localized immediately.
- Do not drag in scope creep. Do not add new functionality to the tests
along the way, and do not fix product bugs you find inside the refactoring —
break those out into a separate item/task (for adding missing tests there is
the unit-coverage-gap skill).
METHODOLOGY (the pipeline)
- Detect the test stack from the repository (pytest / jest / vitest / go
test / JUnit / RSpec / PHPUnit …) and its idioms: how the project
parametrizes, where it keeps fixtures/factories/helpers, what the naming is,
what the coverage tool is.
- Measure the before metrics: number of tests, lines of test code, run
time of the whole suite, coverage (lines and branches). Run the suite — it
must be green (if it is already red/flaky, that is a separate task;
refactoring on top of instability is not allowed — stabilize first or flag
it).
- Take an inventory of anti-patterns (see the catalog below): walk the
SCOPE tests, marking file:line and the problem class. Rate each by the
benefit/risk ratio.
- Refactor one problem class at a time, in small steps, running the suite
between changes. Preserve WHAT is checked.
- Verify the invariant: re-run the whole suite (green), re-measure coverage
(not below baseline), check with a mutation mindset that the key tests still
fail when the product is broken.
- Measure the after metrics and compare with the baseline.
CATALOG OF ANTI-PATTERNS AND HOW TO FIX THEM
- Duplication (copy-paste)
- Symptom: the same setup/sequence of actions/asserts repeats across many
tests; a contract change requires manual edits in a dozen places.
- Fix: extract the common setup into a fixture/factory/builder, the
repeated checks into an assert helper, a family of "input→expectation"
into a parametrization (
@pytest.mark.parametrize, test.each,
table-driven). Do NOT overdo it: excessive abstraction (DRY at any cost)
makes a test unreadable — a test must stay understandable locally.
- Brittle asserts / locators
- Symptom: an assert on the whole object/whole string/exact JSON, breaks on
an irrelevant field; UI locators by index/full XPath/text; comparison
against an exact timestamp/UUID.
- Fix: assert the relevant fields/invariants, not everything at once; use
robust locators (role/
data-testid, not a brittle path); for generated
values check the format/presence, not a literal match. Do not weaken it
into meaninglessness — the assert must remain a check.
- Several unrelated checks in one test
- Symptom: one test checks create, update, and delete all at once; the first
failed assert hides the rest; it is unclear what exactly broke.
- Fix: split into separate tests, one behavior each (one logical
assert-concept per test). Keeping related checks of a single result
together is acceptable.
- Order dependence / shared state
- Symptom: the test relies on state left behind by a neighbor; fails under
order randomization.
- Fix: isolate — fresh state per test (a fixture with cleanup, a
transaction with rollback, a reset of mocks/cache in teardown). Make the
tests independent (verify with randomization). (If this shows up as
instability — see the flaky-test-triage skill.)
- Slow tests
- Symptom: the test hits the real network/DB/FS, sleeps a fixed sleep,
spins up a heavy environment just to check pure logic.
- Fix: mock the I/O at the boundary; replace
sleep with an explicit
wait; drop the check to the right level of the pyramid (see item 6); reuse
expensive fixtures with the right scope (session/module) where it is safe.
Measure the time before/after.
- Redundant E2E where a unit would do (pyramid imbalance)
- Symptom: a business rule/validation/branch is checked by a heavy E2E test
through the whole stack, though it is pure logic; dozens of slow E2E tests
duplicate what a fast unit test would cover.
- Fix: rebalance the pyramid — move the logic check to the
unit/integration level, keep E2E only for end-to-end user scenarios
(smoke/critical path). Do not delete E2E without making sure the logic is
covered below (otherwise coverage is lost).
- Over-mocking (the test checks mocks, not behavior)
- Symptom: so much is mocked that the test only checks that the mocks were
called with the arguments it set itself (a tautology); rewriting the
implementation breaks the test though behavior did not change.
- Fix: mock only the external boundaries (network/DB/time/FS), not the
internal logic of the module under test; check the observable
result/effect, not the fact that internal methods were called. Where
appropriate, replace a mock with a real lightweight object/fake.
- Unclear names and structure
- Symptom:
test_1, test_it_works; it is unclear what the scenario is;
everything is dumped together with no separation of setup/action/check.
- Fix: descriptive names (what is expected under what conditions:
returns_403_if_other_company); an Arrange-Act-Assert
(Given-When-Then) structure with visual separation. The test name = its
specification.
- Magic numbers / data
- Symptom:
assert result == 42, user_id=7 without explanation, a "magic"
literal whose meaning only the author knows.
- Fix: named constants/fixtures with meaningful names; explain the origin of
the expected value (a comment/name) so that an edit does not become
guesswork.
- No negative cases
- Symptom: tests only for the "happy path"; errors/boundaries/invalid input
are not checked.
- Fix: within the refactoring you may fill in obviously missing negative
cases next to the existing ones (a boundary, an exception, invalid input),
but large coverage growth is already unit-coverage-gap; do not turn the
refactoring into writing a new suite.
- Dead / commented-out / always-green tests
- Symptom:
skip/xfail without a reason, commented-out tests, a test
without asserts, a test that cannot fail.
- Fix: delete the dead ones (recording it in the report) or fix/uncomment
them with a meaningful assert; an always-green test either strengthen or
delete.
EDGE CASES THAT ARE OFTEN MISSED
- Parametrization swallowed a case: while collapsing duplicates into a
table, one input or one assert was silently lost — coverage/behavior sagged
unnoticed. Check the number of logical checks before/after.
- An extracted assert helper got weaker: the shared helper checks less than
the original copies checked separately.
- A fixture scope change broke isolation: you moved a fixture from function
to module/session for speed — and got state leakage/flakiness.
- You deleted E2E but the logic did not go down — coverage is formally the
same by lines, but no one checks the end-to-end scenario anymore.
- You removed a "duplicate" test that actually checked a different case —
outwardly similar, semantically distinct.
- Refactoring under an unstable suite: if the tests are already flaky,
"before" and "after" are not comparable — stabilize first.
- Replacing a mock with a real object dragged the network/DB into the test
— it became "more honest" but slower/less stable; watch the boundary.
- Snapshot tests: a mass update of snapshots "so it goes green" may cement
broken behavior as the reference — update consciously.
- You changed the naming/file structure — and broke the runner's test
discovery (name pattern, discovery).
- A shared builder with defaults hid important differences in the inputs —
tests came to look the same where the difference is essential.
- Loss of a comment that explained a non-obvious expected result — while
rewriting, the knowledge of why exactly this value is expected disappeared.
DEFINITION OF DONE (DoD)
- The before baseline metrics are taken (test/line count, run time, line and
branch coverage) on a green suite.
- The eliminated anti-patterns are listed with file:line and the fix method.
- WHAT is checked is preserved: coverage (lines AND branches) is not below
baseline; the number of logical checks did not decrease covertly (deliberate
deletions of dead tests — as a separate item).
- The whole suite is run after refactoring and is green; the key tests still
fail when the product is genuinely broken (checked with a mutation mindset /
mutation testing).
- The after metrics are taken and compared with before (fewer
duplicates/lines, faster run, coverage not dropped).
- The refactoring is in the project's idioms; no scope creep was introduced
(new functionality/product bug fixes are broken out separately).
REPORT FORMAT
- One-line summary: the suite is refactored — N anti-patterns eliminated,
duplicates/lines/run time reduced, coverage preserved (X% lines / Y branches
→ not below).
- SCOPE — which tests were refactored and how the perimeter was
determined; what was left out of the perimeter.
- Test stack and coverage tool — what was detected and by which commands
it was measured/run.
- Before/after metrics — a table: number of tests, lines of test code,
(approximate) number of duplicates, run time, line coverage, branch
coverage.
- What was changed and why — a list of edits: file:line, anti-pattern
class, what was done, how the behavior invariant was preserved.
- Proof that behavior was preserved — the "after" run is green (output),
coverage did not drop (numbers), the result of the mutation-mindset/mutation
testing check on the key tests.
- Deliberate deletions — which dead/duplicate/always-green tests were
deleted and why this is not a loss of coverage.
- Broken out separately (scope creep, not done here) — product bugs found,
large coverage gaps (→ unit-coverage-gap), instability (→ flaky-test-triage).
- What could not be verified — limitations (no environment for some
integration/E2E, mutation testing not set up, etc.).
EXECUTION (practical instructions)
- YOURSELF, in the main thread, perform the SCOPE block — determine the suite
to refactor from
$ARGUMENTS/context. Do not delegate: a subagent does not
see the dialog context. Record the SCOPE.
- YOURSELF detect the test stack and take the before baseline metrics on a
green run — this is the invariant's baseline.
- Take an inventory of anti-patterns across the SCOPE. If the suite is large
and the Agent tool is available, split it into independent zones (by
file/directory) and launch a subagent per zone. Give each: the specific
paths, the detected test stack and the run/coverage commands, the relevant
sections of this skill (the anti-pattern catalog, edge cases, DoD — the
subagent does not see the file itself) and the requirement: refactor in
small steps, run the suite between steps, return the "before/after" metrics
and confirmation that coverage did not drop.
- Refactor one problem class at a time, running the suite between changes.
- When done, run the whole SCOPE suite in full, re-measure coverage, compare
with the baseline metrics.
- Consolidate into a report per the format above. Store the inventory and
metrics in a file, not only in context.
This is an authoring skill: edit the tests so as to preserve the checked
behavior and coverage, and make the tests readable, fast, and robust in the
project's idioms. If the refactoring uncovered a real product bug — do not
"paper over" it by tuning the test, break it out as a separate item.
1---2name: test-refactor3description: Test refactoring without losing coverage4---56# Test refactoring without losing coverage78You are an engineer bringing a test suite into shape. Bad tests are technical9debt: duplicates make changes expensive, brittle asserts break on harmless10edits, slow E2E tests drag down CI, over-mocking checks the mocks instead of11behavior. Your job is to improve the structure, readability, speed, and12robustness of the tests, **without changing WHAT they check** and without13losing coverage.1415The main invariant of refactoring: the observable behavior of the suite is16unchanged. Before and after — the whole suite is run, coverage (lines AND17branches) does not drop, and the tests still fail when the product code is18genuinely broken. The discipline is evidence over assertion: improvements are19confirmed by before/after metrics (test/line count, duplicates, run time,20coverage) and by the run itself, not by a feeling that "it got cleaner".2122Work in the project's conventions: first detect the test stack, and refactor in23its idioms (its way of parametrizing, of fixtures, of helpers). If the suite is24large, split it into zones and delegate to subagents via the Agent tool.2526## INPUT / SCOPE (how to determine the perimeter)2728Perimeter: `$ARGUMENTS`2930The input may arrive in one of several forms:3132- **A. CODE: a test file / directory / suite / branch / diff** — the perimeter33 = the given test files + their shared fixtures/helpers/factories/base classes34 (refactoring them affects all consumers) + the product code that these tests35 cover (needed so as not to lose coverage and to understand the contract). The36 perimeter is ALWAYS wider than the literal input: editing a shared fixture37 affects all tests that use it — include them.38- **B. A DOCUMENT / test guideline** (.md/.txt) — if the project's test39 standard is given, extract its rules (naming, structure, what to mock) and40 bring the existing tests into line with them; a divergence of the tests from41 the standard is the target of the refactoring.42- **C. A TRACKER ISSUE** (ID/link) — fetch the text via an available43 integration (MCP, if connected; otherwise ask the user). Find the mentioned44 tests and related commits (`git log --all --grep=<ID>`).4546If it is unclear which tests to refactor, stop and clarify; do not rewrite the47whole suite at random. Record the SCOPE at the start of the report.4849## KEY PRINCIPLE: REFACTORING DOES NOT CHANGE WHAT IS CHECKED50511. **Behavior invariant.** Refactoring changes the form of a test, not its52 subject. If after the "refactoring" the test checks something else (or stops53 checking), that is not refactoring — it is a coverage regression.542. **Safety net — a run before.** Before touching the tests, run the whole55 suite and record baseline metrics (how many tests, are they green, time,56 coverage). Without a baseline you cannot prove behavior was preserved.573. **Coverage must not drop.** Measure coverage before and after. Especially58 dangerous: when merging duplicates into a parametrization or extracting59 asserts into a helper, accidentally dropping a case or weakening a check.604. **The test must still catch a break.** After refactoring, check with a61 mutation mindset (or mutation testing, if available): break the product code62 — the test must fail. "Green after refactoring" ≠ "still meaningful".635. **Small steps, with a run between.** Do not rewrite a file in one sweep.64 Refactor one anti-pattern at a time, running the suite between steps — that65 way a regression is localized immediately.666. **Do not drag in scope creep.** Do not add new functionality to the tests67 along the way, and do not fix product bugs you find inside the refactoring —68 break those out into a separate item/task (for adding missing tests there is69 the unit-coverage-gap skill).7071## METHODOLOGY (the pipeline)72731. **Detect the test stack** from the repository (pytest / jest / vitest / go74 test / JUnit / RSpec / PHPUnit …) and its idioms: how the project75 parametrizes, where it keeps fixtures/factories/helpers, what the naming is,76 what the coverage tool is.772. **Measure the before metrics**: number of tests, lines of test code, run78 time of the whole suite, coverage (lines and branches). Run the suite — it79 must be green (if it is already red/flaky, that is a separate task;80 refactoring on top of instability is not allowed — stabilize first or flag81 it).823. **Take an inventory of anti-patterns** (see the catalog below): walk the83 SCOPE tests, marking file:line and the problem class. Rate each by the84 benefit/risk ratio.854. **Refactor one problem class at a time**, in small steps, running the suite86 between changes. Preserve WHAT is checked.875. **Verify the invariant**: re-run the whole suite (green), re-measure coverage88 (not below baseline), check with a mutation mindset that the key tests still89 fail when the product is broken.906. **Measure the after metrics** and compare with the baseline.9192## CATALOG OF ANTI-PATTERNS AND HOW TO FIX THEM93941. **Duplication (copy-paste)**95 - Symptom: the same setup/sequence of actions/asserts repeats across many96 tests; a contract change requires manual edits in a dozen places.97 - Fix: extract the common setup into a **fixture/factory/builder**, the98 repeated checks into an **assert helper**, a family of "input→expectation"99 into a **parametrization** (`@pytest.mark.parametrize`, `test.each`,100 table-driven). Do NOT overdo it: excessive abstraction (DRY at any cost)101 makes a test unreadable — a test must stay understandable locally.1022. **Brittle asserts / locators**103 - Symptom: an assert on the whole object/whole string/exact JSON, breaks on104 an irrelevant field; UI locators by index/full XPath/text; comparison105 against an exact timestamp/UUID.106 - Fix: assert the **relevant** fields/invariants, not everything at once; use107 robust locators (role/`data-testid`, not a brittle path); for generated108 values check the format/presence, not a literal match. Do not weaken it109 into meaninglessness — the assert must remain a check.1103. **Several unrelated checks in one test**111 - Symptom: one test checks create, update, and delete all at once; the first112 failed assert hides the rest; it is unclear what exactly broke.113 - Fix: **split** into separate tests, one behavior each (one logical114 assert-concept per test). Keeping related checks of a single result115 together is acceptable.1164. **Order dependence / shared state**117 - Symptom: the test relies on state left behind by a neighbor; fails under118 order randomization.119 - Fix: **isolate** — fresh state per test (a fixture with cleanup, a120 transaction with rollback, a reset of mocks/cache in teardown). Make the121 tests independent (verify with randomization). (If this shows up as122 instability — see the flaky-test-triage skill.)1235. **Slow tests**124 - Symptom: the test hits the real network/DB/FS, sleeps a fixed sleep,125 spins up a heavy environment just to check pure logic.126 - Fix: **mock the I/O** at the boundary; replace `sleep` with an explicit127 wait; drop the check to the right level of the pyramid (see item 6); reuse128 expensive fixtures with the right scope (session/module) where it is safe.129 Measure the time before/after.1306. **Redundant E2E where a unit would do (pyramid imbalance)**131 - Symptom: a business rule/validation/branch is checked by a heavy E2E test132 through the whole stack, though it is pure logic; dozens of slow E2E tests133 duplicate what a fast unit test would cover.134 - Fix: **rebalance the pyramid** — move the logic check to the135 unit/integration level, keep E2E only for end-to-end user scenarios136 (smoke/critical path). Do not delete E2E without making sure the logic is137 covered below (otherwise coverage is lost).1387. **Over-mocking (the test checks mocks, not behavior)**139 - Symptom: so much is mocked that the test only checks that the mocks were140 called with the arguments it set itself (a tautology); rewriting the141 implementation breaks the test though behavior did not change.142 - Fix: mock only the **external boundaries** (network/DB/time/FS), not the143 internal logic of the module under test; check the observable144 **result/effect**, not the fact that internal methods were called. Where145 appropriate, replace a mock with a real lightweight object/fake.1468. **Unclear names and structure**147 - Symptom: `test_1`, `test_it_works`; it is unclear what the scenario is;148 everything is dumped together with no separation of setup/action/check.149 - Fix: **descriptive names** (what is expected under what conditions:150 `returns_403_if_other_company`); an **Arrange-Act-Assert**151 (Given-When-Then) structure with visual separation. The test name = its152 specification.1539. **Magic numbers / data**154 - Symptom: `assert result == 42`, `user_id=7` without explanation, a "magic"155 literal whose meaning only the author knows.156 - Fix: named constants/fixtures with meaningful names; explain the origin of157 the expected value (a comment/name) so that an edit does not become158 guesswork.15910. **No negative cases**160 - Symptom: tests only for the "happy path"; errors/boundaries/invalid input161 are not checked.162 - Fix: within the refactoring you may **fill in** obviously missing negative163 cases next to the existing ones (a boundary, an exception, invalid input),164 but large coverage growth is already unit-coverage-gap; do not turn the165 refactoring into writing a new suite.16611. **Dead / commented-out / always-green tests**167 - Symptom: `skip`/`xfail` without a reason, commented-out tests, a test168 without asserts, a test that cannot fail.169 - Fix: delete the dead ones (recording it in the report) or fix/uncomment170 them with a meaningful assert; an always-green test either strengthen or171 delete.172173## EDGE CASES THAT ARE OFTEN MISSED174175- **Parametrization swallowed a case**: while collapsing duplicates into a176 table, one input or one assert was silently lost — coverage/behavior sagged177 unnoticed. Check the number of logical checks before/after.178- **An extracted assert helper got weaker**: the shared helper checks less than179 the original copies checked separately.180- **A fixture scope change broke isolation**: you moved a fixture from function181 to module/session for speed — and got state leakage/flakiness.182- **You deleted E2E but the logic did not go down** — coverage is formally the183 same by lines, but no one checks the end-to-end scenario anymore.184- **You removed a "duplicate" test that actually checked a different case** —185 outwardly similar, semantically distinct.186- **Refactoring under an unstable suite**: if the tests are already flaky,187 "before" and "after" are not comparable — stabilize first.188- **Replacing a mock with a real object dragged the network/DB into the test**189 — it became "more honest" but slower/less stable; watch the boundary.190- **Snapshot tests**: a mass update of snapshots "so it goes green" may cement191 broken behavior as the reference — update consciously.192- **You changed the naming/file structure — and broke the runner's test193 discovery** (name pattern, discovery).194- **A shared builder with defaults hid important differences in the inputs** —195 tests came to look the same where the difference is essential.196- **Loss of a comment that explained a non-obvious expected result** — while197 rewriting, the knowledge of why exactly this value is expected disappeared.198199## DEFINITION OF DONE (DoD)200201- The before baseline metrics are taken (test/line count, run time, line and202 branch coverage) on a green suite.203- The eliminated anti-patterns are listed with file:line and the fix method.204- WHAT is checked is preserved: coverage (lines AND branches) is not below205 baseline; the number of logical checks did not decrease covertly (deliberate206 deletions of dead tests — as a separate item).207- The whole suite is run after refactoring and is green; the key tests still208 fail when the product is genuinely broken (checked with a mutation mindset /209 mutation testing).210- The after metrics are taken and compared with before (fewer211 duplicates/lines, faster run, coverage not dropped).212- The refactoring is in the project's idioms; no scope creep was introduced213 (new functionality/product bug fixes are broken out separately).214215## REPORT FORMAT2162171. **One-line summary**: the suite is refactored — N anti-patterns eliminated,218 duplicates/lines/run time reduced, coverage preserved (X% lines / Y branches219 → not below).2202. **SCOPE** — which tests were refactored and how the perimeter was221 determined; what was left out of the perimeter.2223. **Test stack and coverage tool** — what was detected and by which commands223 it was measured/run.2244. **Before/after metrics** — a table: number of tests, lines of test code,225 (approximate) number of duplicates, run time, line coverage, branch226 coverage.2275. **What was changed and why** — a list of edits: file:line, anti-pattern228 class, what was done, how the behavior invariant was preserved.2296. **Proof that behavior was preserved** — the "after" run is green (output),230 coverage did not drop (numbers), the result of the mutation-mindset/mutation231 testing check on the key tests.2327. **Deliberate deletions** — which dead/duplicate/always-green tests were233 deleted and why this is not a loss of coverage.2348. **Broken out separately (scope creep, not done here)** — product bugs found,235 large coverage gaps (→ unit-coverage-gap), instability (→ flaky-test-triage).2369. **What could not be verified** — limitations (no environment for some237 integration/E2E, mutation testing not set up, etc.).238239## EXECUTION (practical instructions)2402411. YOURSELF, in the main thread, perform the SCOPE block — determine the suite242 to refactor from `$ARGUMENTS`/context. Do not delegate: a subagent does not243 see the dialog context. Record the SCOPE.2442. YOURSELF detect the test stack and take the before baseline metrics on a245 green run — this is the invariant's baseline.2463. Take an inventory of anti-patterns across the SCOPE. If the suite is large247 and the Agent tool is available, split it into independent zones (by248 file/directory) and launch a subagent per zone. Give each: the specific249 paths, the detected test stack and the run/coverage commands, the relevant250 sections of this skill (the anti-pattern catalog, edge cases, DoD — the251 subagent does not see the file itself) and the requirement: refactor in252 small steps, run the suite between steps, return the "before/after" metrics253 and confirmation that coverage did not drop.2544. Refactor one problem class at a time, running the suite between changes.2555. When done, run the whole SCOPE suite in full, re-measure coverage, compare256 with the baseline metrics.2576. Consolidate into a report per the format above. Store the inventory and258 metrics in a file, not only in context.259260This is an authoring skill: edit the tests so as to preserve the checked261behavior and coverage, and make the tests readable, fast, and robust in the262project's idioms. If the refactoring uncovered a real product bug — do not263"paper over" it by tuning the test, break it out as a separate item.264