test-structure-lifecycle

Applies Four-Phase Test and Test Data Builder patterns to structure test lifecycle and fixture data.

Updated Jun 24, 2026
One-click install
npx skills add https://github.com/Hakkadaikon/hymme --skill test-structure-lifecycle-hakkadaikon
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-structure-lifecycle
Source: https://github.com/Hakkadaikon/hymme/tree/main/skills/test-structure-lifecycle
Command: npx skills add https://github.com/Hakkadaikon/hymme --skill test-structure-lifecycle-hakkadaikon

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tests that acquire resources like database connections or temporary files often leak state between runs, causing flaky, order-dependent failures, and complex fixture setup buries the fields that actually matter for each test. This Skill provides the structural patterns to manage resource lifecycle and test data supply cleanly. ## Core Features & Use Cases - Four-Phase Test: Structures tests into setup, exercise, verify, and teardown phases using beforeEach/afterEach hooks, with exception-safe teardown and shuffle-based order-independence checks. - Test Data Builder / Object Mother: Builds complex fixtures via chainable with-methods that override only the fields relevant to each test, keeping default values in one place and logic out of the builder. - Use Case: When a vitest suite opens a TempStore per test and assembles user objects with many fields, apply Four-Phase Test to guarantee cleanup and a Builder like aUser().withRole("admin").build() so each test shows only the difference that drives its result. ## Quick Start Ask the AI to restructure your vitest tests using the Four-Phase Test pattern and a Test Data Builder so resources are always released and each test shows only the fields that affect its outcome.

Frequently Asked Questions about test-structure-lifecycle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write setup and teardown in vitest tests?

Use the Four-Phase Test pattern: place resource allocation in beforeEach and the matching release in afterEach, keeping only exercise and verify in the test body. Write teardown to be exception-safe with try/finally so one failure does not stop later cleanup.

What is a Test Data Builder pattern in unit testing?

A Test Data Builder assembles fixture objects through chainable with-methods that override only the fields relevant to each test, while defaults live in one place. It keeps builders free of calculation or validation logic so tests never drift from production behavior.

When should I use Object Mother vs Test Data Builder?

Use Object Mother when multiple tests reuse the same named canonical data, such as an expired order. Use a Builder when each test needs to highlight which specific fields drive its result, since chainable overrides make the effective difference visible in the test body.

Why do my tests fail when run in random order?

Order-dependent failures usually mean resources leak between tests because teardown is missing or incomplete. Pair every allocation with a release in afterEach, then run vitest with sequence shuffle to confirm tests stay green regardless of execution order.

When is the Four-Phase Test pattern unnecessary?

Four-Phase Test is unnecessary when tests verify pure calculations with no resources to release, since the simpler AAA pattern suffices. Adding teardown phases without anything to clean up violates YAGNI and adds structure without benefit.