Lets say you encounter a bug in the software you work on. Maybe a user informs you of the bug, or you find it yourself. Let's say this bug has been in your software for a little while, and is not a bug you just added in the last hour or so. This implies that your unit tests did not catch the bug.

Here's the process I recommend for fixing the bug:

1) Work out what the problem is.

2) Work out the solution, edit your source files until the bug is fixed.

3) Since the bug was not caught by a unit test, make a unit test that will catch the bug.

4) Undo the bug fix from your source files, and make sure your new unit test catches the bug.

5) Redo the bug fix. Make sure the new unit test passes.

6) Commit the bug fix and the new unit test(s).

7) Think about how the bug got into your source code. Why wasn't it caught by unit tests? How can you improve your unit tests?

8) Think about if there are likely to be any similar bugs in your source code. Can you add unit tests for those possible bugs?

This is not an exact prescription. The ordering of the steps is flexible, and in some cases some steps may be more aspirational than realistic.