Test First Design
Unit testing has become such an important part of the development process that it is a central focal point of XP. In XP, you actually write your unit tests first, and then write the code. This is known as Test First Design.
Test First Design is a required practice in XP. The premise of Test First Design is that quality software can be designed and implemented by using the following iterative process. First, test for a condition that we want our software to fulfill. Initially, this test will fail. Second, write the code necessary to make the test pass. Finally, the code should be refactored periodically. Code can be refactored with confidence because unit tests are in place to detect any problems we may create, and to let us know when we have working code. This process is performed in a series of short iterations that will lead to an effective design. This also helps the developer to stay focused on implementing only what is needed.
Without the benefits that unit testing provides, development methodologies such as XP would not be possible. Even if your team is using a more traditional development methodology, unit testing can provide the same level of benefits and should be regarded as a critical part of all software development.
NOTE
In XP, unit tests are written first, and then the code they are designed to test follows. This is known as Test First Design. Writing tests first places the emphasis on how the class will be used, and therefore on coding only what is needed. This is also a good strategy for fixing bugs because it catches the presence of the bug immediately. Then write the code to pass the unit test. This way, you'll add to the overall suite of unit tests that are run, and you will catch the bug if it's ever reintroduced. You'll also ensure that your unit test works correctly.