<p>Lots of people talk about writing tests for their code before they start writing their code. This practice is generally known as Test Driven Development or TDD for short. What benefits do I gain from writing software this way? How do I get started with this practice?</p>

[{'answer_id': 4308, 'author': 'Karl Seguin', 'author_id': 34, 'author_profile': 'https://Stackoverflow.com/users/34', 'pm_score': 2, 'selected': False, 'text': '<p>The benefits part has <a href="https://stackoverflow.com/questions/2260/what-is-tdd">recently been covered</a>, as for where to start....on a small enterprisey system where there aren\'t too many unknowns so the risks are low. If you don\'t already know a testing framework (like NUnit), start by learning that. Otherwise start by writing your first test :)</p>\n'}, {'answer_id': 4309, 'author': 'Ed.', 'author_id': 522, 'author_profile': 'https://Stackoverflow.com/users/522', 'pm_score': -1, 'selected': False, 'text': '<p>In my opinion, the single greatest thing is that it clearly allows you to see if your code does what it is supposed to.  This may seem obvious, but it is super easy to run astray of your original goals, as I have found out in the past :p</p>\n'}, {'answer_id': 4310, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 6, 'selected': True, 'text': '<p>There are a lot of benefits:</p>\n\n<ul>\n<li>You get immediate feedback on if your code is working, so you can find bugs faster</li>\n<li>By seeing the test go from red to green, you know that you have both a working regression test, and working code</li>\n<li>You gain confidence to refactor existing code, which means you can clean up code without worrying what it might break</li>\n<li>At the end you have a suite of regression tests that can be run during automated builds to give you greater confidence that your codebase is solid</li>\n</ul>\n\n<p>The best way to start is to just start.  There is a great <a href="https://rads.stackoverflow.com/amzn/click/com/0321146530" rel="noreferrer" rel="nofollow noreferrer">book by Kent Beck</a> all about Test Driven Development.  Just start with new code, don\'t worry about old code... whenever you feel you need to refactor some code, write a test for the existing functionality, then refactor it and make sure the tests stay green.  Also, read <a href="http://devver.wordpress.com/2008/07/07/tips-for-unit-testing/" rel="noreferrer">this great article</a>.</p>\n'}, {'answer_id': 4312, 'author': 'dragonmantank', 'author_id': 204, 'author_profile': 'https://Stackoverflow.com/users/204', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Benefits</strong></p>\n\n<ol>\n<li>You figure out how to compartmentalize your code</li>\n<li>You figure out exactly what you want your code to do</li>\n<li>You know how it supposed to act and, down the road, if refactoring breaks anything</li>\n<li>Gets you in the habit of making sure your code always knows what it is supposed to do</li>\n</ol>\n\n<p><strong>Getting Started</strong></p>\n\n<p>Just do it. Write a test case for what you want to do, and then write code that should pass the test. If you pass your test, great, you can move on to writing cases where your code will always fail (2+2 should not equal 5, for example).</p>\n\n<p>Once all of your tests pass, write your actual business logic to do whatever you want to do. </p>\n\n<p>If you are starting from scratch make sure you find a good testing suite that is easy to use. I like PHP so PHPUnit or SimpleTest work well. Almost all of the popular languages have some xUnit testing suite available to help build and automate testing.</p>\n'}]
['https://Stackoverflow.com/questions/4303', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/358/']