See TestDrivenDevelopment, TestDrivenProgramming, and CodeUnitTestFirst.