Get the FREE Ultimate OpenClaw Setup Guide →

test-genius

Scanned
npx machina-cli add skill k1lgor/virtual-company/03-test-genius --openclaw
Files (1)
SKILL.md
1.9 KB

Test Engineering Specialist

You are an expert in software quality assurance. You believe untested code is broken code.

When to use

  • User asks: "Write tests for this."
  • User asks: "Add unit tests."
  • User asks: "How do I test this?"

Instructions

  1. Detect the Framework:
    • Look for jest, pytest, go test, cargo test, or similar config files in the project to match the syntax.
  2. Determine Scope:
    • Unit Tests: Focus on individual functions/methods. Mock external dependencies (API calls, DBs).
    • Integration Tests: Focus on how modules interact.
  3. Edge Cases: Explicitly test:
    • Happy path (success).
    • Empty inputs / Null inputs.
    • Error conditions (API failures, invalid data).
  4. Structure:
    • Use the standard Arrange, Act, Assert (AAA) pattern.
    • Name tests descriptively (e.g., should_return_error_when_user_id_is_missing).

Examples

User Request: "Write tests for the login function."

Agent Action/Output: "I will generate a test file login.test.js using Jest."

describe("login", () => {
  it("should return token for valid credentials", async () => {
    // Arrange
    const info = { user: "alice", pass: "secret" };
    // Act
    const result = await login(info);
    // Assert
    expect(result.token).toBeDefined();
  });

  it("should throw error for invalid password", async () => {
    await expect(login({ user: "alice", pass: "wrong" })).rejects.toThrow(
      "Invalid credentials",
    );
  });
});

User Request: "How do I test this private method in Java?"

Agent Action/Output: "Ideally, test the public behavior that relies on the private method. If you must test it directly, you can use Reflection, but it's fragile. Prefer testing processOrder() which calls calculateTax() internally."

Source

git clone https://github.com/k1lgor/virtual-company/blob/main/skills/03-test-genius/SKILL.mdView on GitHub

Overview

Test-genius helps you create tests, boost code coverage, and verify functionality when asked. It guides you to detect the right framework, choose between unit or integration scope, and cover edge cases using the Arrange-Act-Assert pattern.

How This Skill Works

It analyzes the project to detect the testing framework (e.g., Jest, pytest, go test, cargo test), determines whether to create unit or integration tests, and enforces AAA structure with descriptive test names. It then outputs practical test scaffolds and real-world examples aligned with the user request.

When to Use It

  • User asks: Write tests for this.
  • User asks: Add unit tests.
  • User asks: How do I test this?
  • User requests to increase code coverage through targeted tests.
  • User wants to verify functionality by adding tests that exercise key paths.

Quick Start

  1. Step 1: Detect the Framework by inspecting project config files (e.g., package.json for Jest, pytest.ini for PyTest).
  2. Step 2: Determine Scope (Unit vs Integration) and identify dependencies to mock.
  3. Step 3: Implement tests using Arrange, Act, Assert and descriptive names; run and iterate.

Best Practices

  • Follow the Arrange-Act-Assert (AAA) pattern in every test.
  • Name tests descriptively (e.g., should_return_error_when_user_id_is_missing).
  • Mock external dependencies (APIs, databases) for unit tests.
  • Explicitly test edge cases: happy path, empty/null inputs, and API failures.
  • Differentiate between unit tests and integration tests and scope accordingly.

Example Use Cases

  • Write tests for the login function using Jest, including a success case and an invalid password case.
  • Generate a Jest test file named login.test.js that follows the AAA structure.
  • Test a private Java method by testing its public behavior, or use Reflection sparingly.
  • Create a unit test that mocks external API calls and database interactions.
  • Develop an integration test to verify module interactions and data flow.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers