A friend of mine who is an agile and extreme programming evangelist used to tell me that developers should get test infected and spread that infection. What he meant by that was that developers should subconsciously follow test driven development (TDD). Test Driven Development is a concept, a practice that says write the test code before writing the actual code. TDD does not belong to any particular development methodology and is just a best practice for developers.
Frameworks like JUnit help creating test code that can automate unit testing. Generally the unit testing code is written after the first version of code is built. What TDD preaches is to write the unit test code first assuming an operational system is available. Definitely the test code will fail because the code needed is missing. So fix the actual code what has been reported as error from the unit test result. Run the unit test again and see if it fails. If it fails write the code that will fix it. Keep doing this until the unit test passes. Basically here the test code is created first and the actual code is built with the execution results of the unit test. The advantage of using a TDD is it can drive the design of the program step by step. It helps the developer to think about the test cases before even the code is ready, this will help him/her think not just the happy path testing but also negative/failure tests. It also helps in catching bugs early on. It would look like TDD would take additional development effort but actually it saves in the long run because of reduced rework and great reduction of bugs cropping up when the QA team tests the system. TDD is like an addiction if followed as a discipline. Once addicted its difficult to get out of it as one would really enjoy the benefits of it.