Repaso
Español
TestingCoreTST-15

You are fixing a production bug. What is the recommended first step in code?

Options

  1. Fix it directly in the code and deploy it
  2. Write a failing test that reproduces the bug (Correct option)
  3. Add more logging only and wait for it to happen
  4. Rewrite the whole module that has the bug

Answer

Write a test that reproduces the bug and fails, then fix it so the test passes

Why

A failing test proves you understood and reproduced the bug. When it turns green, you know the fix works.

The test then stays in the suite as a regression test: if anyone reintroduces the bug later, it fails immediately.

Remember

Bug fix = failing test first, then the fix.

Key terms

Practice this question in Repaso