Test driven development

From microsoft/FluidFramework · View interactive version

Test driven development is an AI agent skill from the GitHub repository microsoft/FluidFramework. Use when implementing any feature or bugfix, before writing implementation code - write the test first, watch it fail, write minimal code to pass; ensures tests actually verify behavior by requiring failure first

How to use this skill

Skill file

<required>

CRITICAL Add the following steps to your Todo list using TodoWrite:

  1. Write failing tests (RED phase)
  1. Create a subagent using the nori-task-runner to evaluate test quality.
  1. Verify the test fails due to the behavior of the application, and NOT due to the test.

<system-reminder>If you have more than one test that you need to write, you should write all of them before moving to the GREEN phase.</system-reminder>

  1. Write the minimal amount of code necessary to make the test pass (GREEN phase)
  2. Verify the test now passes due to the behavior of the application.
  1. Refactor the code to clean it up.
  2. Verify tests still pass.

</required>

RED - Write Failing Test

Write one minimal test showing what should happen.

<good-example>

test('retries failed operations 3 times', async () => {
  let attempts = 0;
  const operation = () => {
    attempts++;
    if (attempts < 3) throw new Error('fail');
    return 'success';
  };

  const result = await foobar.retryOperation(operation);

  expect(result).toBe('success');
  expect(attempts).toBe(3);
});

Clear name, tests real behavior, one thing. Note that the tested operation is

imported -- this is a STRONG sign that this is testing something real.

</good-example>

<bad-example>

test('retry works', async () => {
  const mock = jest
    .fn()
    .mockRejectedValueOnce(new Error())
    .mockRejectedValueOnce(new Error())
    .mockResolvedValueOnce('success');
  await retryOperation(mock);
  expect(mock).toHaveBeenCalledTimes(3);
});

Vague name, tests mock not code

</bad-example>

Verify RED - Watch It Fail

npm test path/to/test.test.ts

Confirm:

GREEN - Minimal Code

Write simplest code to pass the test.

<good-example>

async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
  for (let i = 0; i < 3; i++) {
    try {
      return await fn();
    } catch (e) {
      if (i === 2) throw e;
    }
  }
  throw new Error('unreachable');
}

Just enough to pass

</good-example>

<bad-example>

async function retryOperation<T>(
  fn: () => Promise<T>,
  options?: {
    maxRetries?: number;
    backoff?: 'linear' | 'exponential';
    onRetry?: (attempt: number) => void;
  }
): Promise<T> {
  // YAGNI
}

Over-engineered

</bad-example>

Don't add features, refactor other code, or "improve" beyond the test.

Verify GREEN - Watch It Pass

npm test path/to/test.test.ts

Confirm:

REFACTOR - Clean Up

After green only:

Keep tests green. Do not add behavior.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.