Back to Cookbook

Test Factory

From zero coverage to "actually tested" in minutes

Point it at a file, function, or module and get useful tests back. This is a strong starter recipe because it works on a small input, gives you code you can review immediately, and teaches you how to steer OpenClaw with examples.

House RecipeWork1 min

INGREDIENTS

🐙GitHub

PROMPT

Write tests for the code I'm about to share. Use the same testing framework and style as my existing tests (I'll share an example if I have one). Cover: (1) happy path for each public function/method, (2) edge cases — null inputs, empty collections, boundary values, type mismatches, (3) error paths — what happens when things fail, (4) mocks/stubs for external dependencies. Name tests descriptively so failures are self-documenting. If I don't specify a framework, ask me what I'm using. Code to test: [paste your code here] Existing test example (optional): [paste an existing test file for style matching]

How It Works

Hand your Claw a function, module, or file and it generates tests that

actually exercise the code — not just happy-path assertions. It reads your

existing test patterns (framework, style, naming conventions) and matches

them.

What You Get

  • Unit tests with meaningful assertions for each public function
  • Edge case coverage: null inputs, empty arrays, boundary values, error paths
  • Mock and stub generation for external dependencies
  • Integration test scaffolding for API endpoints and database queries
  • Tests written in your existing framework (Jest, pytest, Vitest, Go testing, etc.)

Setup Steps

  1. Share the code you want tested — a file, function, or module
  2. Optionally share an existing test file so the Claw matches your style
  3. Review generated tests and tweak as needed
  4. Run them to verify they pass

Tips

  • Share one existing test file for best style matching
  • Ask specifically for edge cases if you want thorough coverage
  • Great for legacy code where nobody wrote tests the first time
  • Run after refactoring to make sure behavior is preserved
  • Pair with your CI pipeline to catch regressions automatically
Tags:#testing#code-quality#automation#development