{"data":{"slug":"discovered-420c2ba90599980baacaf3a922209e71520a1d249c06ccae","title":"Test Behavior, Not Implementation","summary":"Write tests that assert observable behavior through a code's public interface, ensuring they remain valid even when internal implementation details change.","url":"https:\/\/skillshunter.net\/skills\/discovered-420c2ba90599980baacaf3a922209e71520a1d249c06ccae","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-420c2ba90599980baacaf3a922209e71520a1d249c06ccae","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-420c2ba90599980baacaf3a922209e71520a1d249c06ccae.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-420c2ba90599980baacaf3a922209e71520a1d249c06ccae\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure tests focus on observable outcomes such as return values, errors, and external effects, not internal helper methods or data structures. Prepare concrete inputs based on requirements and assert error types that callers would branch on.","instructions":"---\nname: principle-test-behavior-not-implementation\ndescription: In tests, assert observable behavior, not internals.\ndisable-model-invocation: true\n---\n\n# Test Behavior, Not Implementation\n\nA test is a claim about what users of the code can observe through its interface: return values, errors, state they can read back, and effects on outside systems. Private helpers, internal call order, and intermediate data are implementation.\n\nJudge each test against two imagined edits:\n\n- **Break the behavior** (a wrong value, a skipped or doubled effect). If the test still passes, it proves nothing. The usual causes are a loose assertion, an expected value computed by the code under test, and an assertion on data the test built itself.\n- **Change the internals** and keep every observable result. If the test fails, it is pinned to the implementation.\n\nKeep a test that catches the first edit and survives the second. Rewrite or delete the rest. Drive the code through its public interface with a concrete input, and derive the expected value from the requirement. What an external service receives is behavior. A call to an internal helper is not. Pair \"this never happens\" with a case where it does happen. Assert the error type that callers branch on, not the message.\n","use_cases":["Validating that a function returns the correct value after an external system call","Ensuring that an error type is raised when a specific condition occurs","Testing that a method correctly updates a shared state without asserting internal helper calls"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/jueyi6\/empstack\/blob\/74181e31d2f00313f8683ba157966efcabbe109e\/skills\/principle-test-behavior-not-implementation\/SKILL.md","source_commit":"74181e31d2f00313f8683ba157966efcabbe109e","license":null,"version":null,"listing_approved_at":"2026-12-02","created_at":"2026-11-30T08:56:34.000000Z","updated_at":"2026-12-02T09:15:14.000000Z","seo_title":"Test Behavior, Not Implementation","seo_description":"Learn how to write effective tests that focus on observable behavior rather than internal implementation details.","seo_keywords":["test behavior","test implementation","test public interface","test external effects","test error types"]}}