<p>I saw many questions asking 'how' to unit test in a specific language, but no question asking 'what', 'why', and 'when'.</p>

<ul>
<li>What is it?</li>
<li>What does it do for me?</li>
<li>Why should I use it?</li>
<li>When should I use it (also when not)?</li>
<li>What are some common pitfalls and misconceptions</li>
</ul>

[{'answer_id': 1393, 'author': 'Rytmis', 'author_id': 266, 'author_profile': 'https://Stackoverflow.com/users/266', 'pm_score': 9, 'selected': True, 'text': '<p>Unit testing is, roughly speaking, testing bits of your code in isolation with test code. The immediate advantages that come to mind are:</p>\n\n<ul>\n<li>Running the tests becomes automate-able and repeatable</li>\n<li>You can test at a much more granular level than point-and-click testing via a GUI</li>\n</ul>\n\n<p>Note that if your test code writes to a file, opens a database connection or does something over the network, it\'s more appropriately categorized as an integration test. Integration tests are a good thing, but should not be confused with unit tests. Unit test code should be short, sweet and quick to execute.</p>\n\n<p>Another way to look at unit testing is that you write the tests first. This is known as Test-Driven Development (TDD for short). TDD brings additional advantages:</p>\n\n<ul>\n<li>You don\'t write speculative "I might need this in the future" code -- just enough to make the tests pass</li>\n<li>The code you\'ve written is always covered by tests</li>\n<li>By writing the test first, you\'re forced into thinking about how you want to call the code, which usually improves the design of the code in the long run.</li>\n</ul>\n\n<p>If you\'re not doing unit testing now, I recommend you get started on it. Get a good book, practically any xUnit-book will do because the concepts are very much transferable between them. </p>\n\n<p>Sometimes writing unit tests can be painful. When it gets that way, try to find someone to help you, and resist the temptation to "just write the damn code". Unit testing is a lot like washing the dishes. It\'s not always pleasant, but it keeps your metaphorical kitchen clean, and you really want it to be clean. :)</p>\n\n<hr>\n\n<p>Edit: One misconception comes to mind, although I\'m not sure if it\'s so common. I\'ve heard a project manager say that unit tests made the team write all the code twice. If it looks and feels that way, well, you\'re doing it wrong. Not only does writing the tests usually speed up development, but it also gives you a convenient "now I\'m done" indicator that you wouldn\'t have otherwise.</p>\n'}, {'answer_id': 1398, 'author': 'Karl Seguin', 'author_id': 34, 'author_profile': 'https://Stackoverflow.com/users/34', 'pm_score': 6, 'selected': False, 'text': '<p>I don\'t disagree with Dan (although a better choice may just be not to answer)...but...</p>\n\n<p>Unit testing is the process of writing code to test the behavior and functionality of your system.</p>\n\n<p>Obviously tests improve the quality of your code, but that\'s just a superficial benefit of unit testing. The real benefits are to:</p>\n\n<ol>\n<li>Make it easier to change the technical implementation while making sure you don\'t change the behavior (refactoring). Properly unit tested code can be aggressively refactored/cleaned up with little chance of breaking anything without noticing it.</li>\n<li>Give developers confidence when adding behavior or making fixes.</li>\n<li>Document your code</li>\n<li>Indicate areas of your code that are tightly coupled. It\'s hard to unit test code that\'s tightly coupled</li>\n<li>Provide a means to use your API and look for difficulties early on</li>\n<li>Indicates methods and classes that aren\'t very cohesive</li>\n</ol>\n\n<p>You should unit test because its in your interest to deliver a maintainable and quality product to your client.</p>\n\n<p>I\'d suggest you use it for any system, or part of a system, which models real-world behavior. In other words, it\'s particularly well suited for enterprise development. I would not use it for throw-away/utility programs. I would not use it for parts of a system that are problematic to test (UI is a common example, but that isn\'t always the case)</p>\n\n<p>The greatest pitfall is that developers test too large a unit, or they consider a method a unit. This is particularly true if you don\'t understand <a href="https://en.wikipedia.org/wiki/Inversion_of_control" rel="noreferrer">Inversion of Control</a> - in which case your unit tests will always turn into end-to-end integration testing. Unit test should test individual behaviors - and most methods have many behaviors.</p>\n\n<p>The greatest misconception is that programmers shouldn\'t test. Only bad or lazy programmers believe that. Should the guy building your roof not test it? Should the doctor replacing a heart valve not test the new valve? Only a programmer can test that his code does what he intended it to do (QA can test edge cases - how code behaves when it\'s told to do things the programmer didn\'t intend, and the client can do acceptance test - does the code do what what the client paid for it to do)</p>\n'}, {'answer_id': 1718, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 2, 'selected': False, 'text': '<p>This is my take on it. I would say unit testing is the practice of writing software tests to verify that your real software does what it is meant to. This started with <a href="http://junit.org/" rel="noreferrer">jUnit</a> in the Java world and has become a best practice in PHP as well with <a href="http://simpletest.org/" rel="noreferrer">SimpleTest</a> and <a href="http://www.phpunit.de/" rel="noreferrer">phpUnit</a>. It\'s a core practice of Extreme Programming and helps you to be sure that your software still works as intended after editing. If you have sufficient test coverage, you can do major refactoring, bug fixing or add features rapidly with much less fear of introducing other problems.</p>\n\n<p>It\'s most effective when all unit tests can be run automatically.</p>\n\n<p>Unit testing is generally associated with OO development. The basic idea is to create a script which sets up the environment for your code and then exercises it; you write assertions, specify the intended output that you should receive and then execute your test script using a framework such as those mentioned above.</p>\n\n<p>The framework will run all the tests against your code and then report back success or failure of each test. phpUnit is run from the Linux command line by default, though there are HTTP interfaces available for it. SimpleTest is web-based by nature and is much easier to get up and running, IMO. In combination with xDebug, phpUnit can give you automated statistics for code coverage which some people find very useful.</p>\n\n<p>Some teams write hooks from their subversion repository so that unit tests are run automatically whenever you commit changes.</p>\n\n<p>It\'s good practice to keep your unit tests in the same repository as your application.</p>\n'}, {'answer_id': 12528, 'author': 'Guy', 'author_id': 1463, 'author_profile': 'https://Stackoverflow.com/users/1463', 'pm_score': 2, 'selected': False, 'text': '<p>Unit-testing is the testing of a unit of code (e.g. a single function) without the need for the infrastructure that that unit of code relies on. i.e. test it in isolation.</p>\n\n<p>If, for example, the function that you\'re testing connects to a database and does an update, in a unit test you might not want to do that update. You would if it were an integration test but in this case it\'s not.</p>\n\n<p>So a unit test would exercise the functionality enclosed in the "function" you\'re testing without side effects of the database update.</p>\n\n<p>Say your function retrieved some numbers from a database and then performed a standard deviation calculation. What are you trying to test here? That the standard deviation is calculated correctly or that the data is returned from the database?</p>\n\n<p>In a unit test you just want to test that the standard deviation is calculated correctly. In an integration test you want to test the standard deviation calculation and the database retrieval.</p>\n'}, {'answer_id': 23070, 'author': 'SarekOfVulcan', 'author_id': 2531, 'author_profile': 'https://Stackoverflow.com/users/2531', 'pm_score': 1, 'selected': False, 'text': "<p>I went to a presentation on unit testing at FoxForward 2007 and was told never to unit test anything that works with data. After all, if you test on live data, the results are unpredictable, and if you don't test on live data, you're not actually testing the code you wrote. Unfortunately, that's most of the coding I do these days. :-)</p>\n\n<p>I did take a shot at TDD recently when I was writing a routine to save and restore settings. First, I verified that I could create the storage object. Then, that it had the method I needed to call. Then, that I could call it. Then, that I could pass it parameters. Then, that I could pass it specific parameters. And so on, until I was finally verifying that it would save the specified setting, allow me to change it, and then restore it, for several different syntaxes.</p>\n\n<p>I didn't get to the end, because I needed-the-routine-now-dammit, but it was a good exercise.</p>\n"}, {'answer_id': 23096, 'author': 'Adam V', 'author_id': 517, 'author_profile': 'https://Stackoverflow.com/users/517', 'pm_score': 1, 'selected': False, 'text': "<blockquote>\n<p>What do you do if you are given a pile of crap and seem like you are stuck in a perpetual state of cleanup that you know with the addition of any new feature or code can break the current set because the current software is like a house of cards?</p>\n<p>How can we do unit testing then?</p>\n</blockquote>\n<p>You start small. The project I just got into had no unit testing until a few months ago. When coverage was that low, we would simply pick a file that had no coverage and click &quot;add tests&quot;.</p>\n<p>Right now we're up to over 40%, and we've managed to pick off most of the low-hanging fruit.</p>\n<p>(The best part is that even at this low level of coverage, we've already run into many instances of the code doing the wrong thing, and the testing caught it. That's a huge motivator to push people to add more testing.)</p>\n"}, {'answer_id': 25386, 'author': 'reefnet_alex', 'author_id': 2745, 'author_profile': 'https://Stackoverflow.com/users/2745', 'pm_score': 4, 'selected': False, 'text': '<p>Chipping in on the philosophical pros of unit testing and TDD here are a few of they key "lightbulb" observations which struck me on my tentative first steps on the road to TDD enlightenment (none original or necessarily news)...</p>\n\n<ol>\n<li><p>TDD does NOT mean writing twice the amount of code. Test code is typically fairly quick and painless to write and is a key part of your design process and critically.</p></li>\n<li><p>TDD helps you to realize when to stop coding! Your tests give you confidence that you\'ve done enough for now and can stop tweaking and move on to the next thing.</p></li>\n<li><p>The tests and the code work together to achieve better code. Your code could be bad / buggy. Your TEST could be bad / buggy. In TDD you are banking on the chances of BOTH being bad / buggy being fairly low. Often its the test that needs fixing but that\'s still a good outcome. </p></li>\n<li><p>TDD helps with coding constipation. You know that feeling that you have so much to do you barely know where to start? It\'s Friday afternoon, if you just procrastinate for a couple more hours... TDD allows you to flesh out very quickly what you think you need to do, and gets your coding moving quickly. Also, like lab rats, I think we all respond to that big green light and work harder to see it again!</p></li>\n<li><p>In a similar vein, these designer types can SEE what they\'re working on. They can wander off for a juice / cigarette / iphone break and return to a monitor that immediately gives them a visual cue as to where they got to. TDD gives us something similar. It\'s easier to see where we got to when life intervenes...</p></li>\n<li><p>I think it was Fowler who said: "Imperfect tests, run frequently, are much better than perfect tests that are never written at all". I interprete this as giving me permission to write tests where I think they\'ll be most useful even if the rest of my code coverage is woefully incomplete.</p></li>\n<li><p>TDD helps in all kinds of surprising ways down the line. Good unit tests can help document what something is supposed to do, they can help you migrate code from one project to another and give you an unwarranted feeling of superiority over your non-testing colleagues :)</p></li>\n</ol>\n\n<p><a href="http://www.masukomi.org/talks/unit_testing_talk_2/index.xul?data=slide_data.txt#page1" rel="noreferrer">This presentation</a> is an excellent introduction to all the yummy goodness testing entails.</p>\n'}, {'answer_id': 25405, 'author': 'bruceatk', 'author_id': 791, 'author_profile': 'https://Stackoverflow.com/users/791', 'pm_score': 2, 'selected': False, 'text': '<p>Test Driven Development has sort of taken over the term Unit Test.  As an old timer I will mention the more generic definition of it.</p>\n\n<p>Unit Test also means testing a single component in a larger system. This single component could be a dll, exe, class library, etc.  It could even be a single system in a multi-system application.  So ultimately Unit Test ends up being the testing of whatever you want to call a single piece of a larger system. </p>\n\n<p>You would then move up to integrated or system testing by testing how all the components work together. </p>\n'}, {'answer_id': 78695, 'author': 'Leah', 'author_id': 5506, 'author_profile': 'https://Stackoverflow.com/users/5506', 'pm_score': 3, 'selected': False, 'text': '<p>I use unit tests to save time.</p>\n\n<p>When building business logic (or data access) testing functionality can often involve typing stuff into a lot of screens that may or may not be finished yet. Automating these tests saves time.</p>\n\n<p>For me unit tests are a kind of modularised test harness. There is usually at least one test per public function. I write additional tests to cover various behaviours. </p>\n\n<p><strong>All the special cases that you thought of when developing the code can be recorded in the code in the unit tests. The unit tests also become a source of examples on how to use the code.</strong></p>\n\n<p>It is a lot faster for me to discover that my new code breaks something in my unit tests then to check in the code and have some front-end developer find a problem.</p>\n\n<p>For data access testing I try to write tests that either have no change or clean up after themselves.</p>\n\n<p>Unit tests aren’t going to be able to solve all the testing requirements. They will be able to save development time and test core parts of the application.</p>\n'}, {'answer_id': 78737, 'author': 'MetroidFan2002', 'author_id': 8026, 'author_profile': 'https://Stackoverflow.com/users/8026', 'pm_score': 2, 'selected': False, 'text': '<p>Use <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=203994" rel="nofollow noreferrer">Testivus</a>. All you need to know is right there :)</p>\n'}, {'answer_id': 101545, 'author': 'Cody Hatch', 'author_id': 17086, 'author_profile': 'https://Stackoverflow.com/users/17086', 'pm_score': 5, 'selected': False, 'text': '<p>I was never taught unit testing at university, and it took me a while to "get" it. I read about it, went "ah, right, automated testing, that could be cool I guess", and then I forgot about it.</p>\n\n<p>It took quite a bit longer before I really figured out the point: Let\'s say you\'re working on a large system and you write a small module. It compiles, you put it through its paces, it works great, you move on to the next task. Nine months down the line and two versions later someone else makes a change to some <em>seemingly</em> unrelated part of the program, and it breaks the module. Worse, they test their changes, and their code works, but they don\'t test your module; hell, they may not even know your module <em>exists</em>.</p>\n\n<p>And now you\'ve got a problem: broken code is in the trunk and nobody even knows. The best case is an internal tester finds it before you ship, but fixing code that late in the game is expensive. And if no internal tester finds it...well, that can get very expensive indeed.</p>\n\n<p>The solution is unit tests. They\'ll catch problems when you write code - which is fine - but you could have done that by hand. The real payoff is that they\'ll catch problems nine months down the line when you\'re now working on a completely different project, but a summer intern thinks it\'ll look tidier if those parameters were in alphabetical order - and then the unit test you wrote way back fails, and someone throws things at the intern until he changes the parameter order back. <strong>That\'s</strong> the "why" of unit tests. :-)</p>\n'}, {'answer_id': 2443006, 'author': 'Oded', 'author_id': 1583, 'author_profile': 'https://Stackoverflow.com/users/1583', 'pm_score': 2, 'selected': False, 'text': '<p>Unit testing is about writing code that tests your application code.</p>\n\n<p>The <em>Unit</em> part of the name is about the intention to test small units of code (one method for example) at a time.</p>\n\n<p>xUnit is there to help with this testing - they are frameworks that assist with this. Part of that is automated test runners that tell you what test fail and which ones pass.</p>\n\n<p>They also have facilities to setup common code that you need in each test before hand and tear it down when all tests have finished.</p>\n\n<p>You can have a test to check that an expected exception has been thrown, without having to write the whole try catch block yourself.</p>\n'}, {'answer_id': 2443012, 'author': 'Péter Török', 'author_id': 265143, 'author_profile': 'https://Stackoverflow.com/users/265143', 'pm_score': 6, 'selected': False, 'text': '<p>The main difference of unit testing, as opposed to "just opening a new project and test this specific code" is that it\'s <em>automated</em>, thus <em>repeatable</em>.</p>\n\n<p>If you test your code manually, it may convince you that the code is working perfectly - <em>in its current state</em>. But what about a week later, when you made a slight modification in it? Are you willing to retest it again by hand whenever <em>anything</em> changes in your code? Most probably not :-(</p>\n\n<p>But if you can <strong>run your tests anytime, with a single click, exactly the same way, within a few seconds</strong>, then they <em>will</em> show you immediately whenever something is broken. And if you also integrate the unit tests into your automated build process, they will alert you to bugs even in cases where a seemingly completely unrelated change broke something in a distant part of the codebase - when it would not even occur to you that there is a need to retest that particular functionality.</p>\n\n<p>This is the main advantage of unit tests over hand testing. But wait, there is more:</p>\n\n<ul>\n<li>unit tests <strong>shorten the development feedback loop</strong> dramatically: with a separate testing department it may take weeks for you to know that there is a bug in your code, by which time you have already forgotten much of the context, thus it may take you hours to find and fix the bug; OTOH with unit tests, the feedback cycle is measured in seconds, and the bug fix process is typically along the lines of an "oh sh*t, I forgot to check for that condition here" :-)</li>\n<li>unit tests effectively <strong>document</strong> (your understanding of) the behaviour of your code</li>\n<li>unit testing forces you to reevaluate your design choices, which results in <strong>simpler, cleaner design</strong></li>\n</ul>\n\n<p>Unit testing frameworks, in turn,  make it easy for you to write and run your tests.</p>\n'}, {'answer_id': 2443017, 'author': 'Rony', 'author_id': 51326, 'author_profile': 'https://Stackoverflow.com/users/51326', 'pm_score': 2, 'selected': False, 'text': '<p>Unit testing is a practice to make sure that the function or module which you are going to implement is going to behave as expected (requirements) and also to make sure how it behaves in scenarios like boundary conditions, and invalid input.</p>\n\n<p><a href="http://en.wikipedia.org/wiki/XUnit" rel="nofollow noreferrer">xUnit</a>, <a href="http://en.wikipedia.org/wiki/NUnit" rel="nofollow noreferrer">NUnit</a>, <a href="http://mbunit.com/" rel="nofollow noreferrer">mbUnit</a>, etc. are tools which help you in writing the tests.</p>\n'}, {'answer_id': 2443018, 'author': 'pierroz', 'author_id': 83125, 'author_profile': 'https://Stackoverflow.com/users/83125', 'pm_score': 2, 'selected': False, 'text': '<p>LibrarIES like <a href="http://en.wikipedia.org/wiki/NUnit" rel="nofollow noreferrer">NUnit</a>, <a href="http://en.wikipedia.org/wiki/XUnit" rel="nofollow noreferrer">xUnit</a> or <a href="http://en.wikipedia.org/wiki/JUnit" rel="nofollow noreferrer">JUnit</a> are just mandatory if you want to develop your projects using the <a href="http://en.wikipedia.org/wiki/Test-driven_development" rel="nofollow noreferrer">TDD</a> approach popularized by Kent Beck:</p>\n\n<p>You can read <em><a href="http://www.agiledata.org/essays/tdd.html" rel="nofollow noreferrer">Introduction to Test Driven Development (TDD)</a></em> or Kent Beck\'s book <em><a href="https://rads.stackoverflow.com/amzn/click/com/0321146530" rel="nofollow noreferrer" rel="nofollow noreferrer">Test Driven Development: By Example</a></em>.</p>\n\n<p>Then, if you want to be sure your tests cover a "good" part of your code, you can use software like <a href="http://en.wikipedia.org/wiki/NCover" rel="nofollow noreferrer">NCover</a>, <a href="http://www.mmsindia.com/JCover.html" rel="nofollow noreferrer">JCover</a>, <a href="http://sourceforge.net/projects/partcover/" rel="nofollow noreferrer">PartCover</a> or whatever. They\'ll tell you the coverage percentage of your code. Depending on how much you\'re adept at TDD, you\'ll know if you\'ve practiced it well enough :)</p>\n'}, {'answer_id': 2443019, 'author': 'Tomas Vana', 'author_id': 199584, 'author_profile': 'https://Stackoverflow.com/users/199584', 'pm_score': 2, 'selected': False, 'text': "<p>First of all, whether speaking about Unit testing or any other kinds of automated testing (Integration, Load, UI testing etc.), the key difference from what you suggest is that it is automated, repeatable and it doesn't require any human resources to be consumed (= nobody has to perform the tests, they usually run at a press of a button).</p>\n"}, {'answer_id': 2443027, 'author': 'AndiDog', 'author_id': 245706, 'author_profile': 'https://Stackoverflow.com/users/245706', 'pm_score': 2, 'selected': False, 'text': '<p>I think the point that you don\'t understand is that unit testing frameworks like NUnit (and the like) will help you in <em>automating</em> small to medium-sized tests. Usually you can run the tests in a GUI (that\'s the case with <a href="http://www.nunit.org/" rel="nofollow noreferrer">NUnit</a>, for instance) by simply clicking a button and then - hopefully - see the progress bar stay green. If it turns red, the framework shows you which test failed and what exactly went wrong. In a normal unit test, you often use assertions, e.g. <code>Assert.AreEqual(expectedValue, actualValue, "some description")</code> - so if the two values are unequal you will see an error saying "some description: expected &lt;expectedValue&gt; but was &lt;actualValue&gt;".</p>\n\n<p>So as a conclusion unit testing will make testing faster and a lot more comfortable for developers. You can run all the unit tests before committing new code so that you don\'t break the build process of other developers on the same project.</p>\n'}, {'answer_id': 2443148, 'author': 'Paul Hildebrandt', 'author_id': 99896, 'author_profile': 'https://Stackoverflow.com/users/99896', 'pm_score': 3, 'selected': False, 'text': '<p>I would like to recommend the xUnit Testing Patterns book by Gerard Meszaros.   It\'s large but is a great resource on unit testing.  Here is a link to his web site where he discusses the basics of unit testing.  <a href="http://xunitpatterns.com/XUnitBasics.html" rel="noreferrer">http://xunitpatterns.com/XUnitBasics.html</a></p>\n'}, {'answer_id': 31494287, 'author': 'Stephen Brown', 'author_id': 5040151, 'author_profile': 'https://Stackoverflow.com/users/5040151', 'pm_score': 1, 'selected': False, 'text': '<p>This answers why you should be doing unit testing.</p>\n\n<hr>\n\n<p>The 3 videos below cover unit testing in javascript but the general principles apply across most languages.</p>\n\n<p>Unit Testing: Minutes Now Will Save Hours Later - Eric Mann -  <a href="https://www.youtube.com/watch?v=_UmmaPe8Bzc" rel="nofollow">https://www.youtube.com/watch?v=_UmmaPe8Bzc</a></p>\n\n<p>JS Unit Testing (very good) - <a href="https://www.youtube.com/watch?v=-IYqgx8JxlU" rel="nofollow">https://www.youtube.com/watch?v=-IYqgx8JxlU</a></p>\n\n<p>Writing Testable JavaScript - <a href="https://www.youtube.com/watch?v=OzjogCFO4Zo" rel="nofollow">https://www.youtube.com/watch?v=OzjogCFO4Zo</a></p>\n\n<hr>\n\n<p>Now I\'m just learning about the subject so I may not be 100% correct and there\'s more to it than what I\'m describing here but my basic understanding of unit testing is that you write some test code (which is kept separate from your main code) that calls a function in your main code with input (arguments) that the function requires and the code then checks if it gets back a valid return value. If it does get back a valid value the unit testing framework that you\'re using to run the tests shows a green light (all good) if the value is invalid you get a red light and you then can fix the problem straight away before you release the new code to production, without testing you may actually not have caught the error.</p>\n\n<p>So you write tests for you current code and create the code so that it passes the test. Months later you or someone else need to modify the function in your main code, because earlier you had already written test code for that function you now run again and the test may fail because the coder introduced a logic error in the function or return something completely different than what that function is supposed to return. Again without the test in place that error might be hard to track down as it can possibly affect other code as well and will go unnoticed.</p>\n\n<hr>\n\n<p>Also the fact that you have a computer program that runs through your code and tests it instead of you manually doing it in the browser page by page saves time (unit testing for javascript). Let\'s say that you modify a function that is used by some script on a web page and it works all well and good for its new intended purpose. But, let\'s also say for arguments sake that there is another function you have somewhere else in your code that depends on that newly modified function for it to operate properly. This dependent function may now stop working because of the changes that you\'ve made to the first function, however without tests in place that are run automatically by your computer you will not notice that there\'s a problem with that function until it is actually executed and you\'ll have to manually navigate to a web page that includes the script which executes the dependent function, only then you notice that there\'s a bug because of the change that you made to the first function.</p>\n\n<p>To reiterate, having tests that are run while developing your application will catch these kinds of problems as you\'re coding. Not having the tests in place you\'d have to manually go through your whole application and even then it can be hard to spot the bug, naively you send it out into production and after a while a kind user sends you a bug report (which won\'t be as good as your error messages in a testing framework).</p>\n\n<hr>\n\n<p>It\'s quite confusing when you first hear of the subject and you think to yourself, am I not already testing my code? And the code that you\'ve written is  working like it is supposed to already, "why do I need another framework?"... Yes you are already testing your code but a computer is better at doing it. You just have to write good enough tests for a function/unit of code once and the rest is taken care of for you by the mighty cpu instead of you having to manually check that all of your code is still working when you make a change to your code.</p>\n\n<p>Also, you don\'t have to unit test your code if you don\'t want to but it pays off as your project/code base starts to grow larger as the chances of introducing bugs increases.</p>\n'}, {'answer_id': 43756257, 'author': 'aap', 'author_id': 1302116, 'author_profile': 'https://Stackoverflow.com/users/1302116', 'pm_score': 0, 'selected': False, 'text': '<p>Unit-testing and TDD in general enables you to have shorter feedback cycles about the software you are writing. Instead of having a large test phase at the very end of the implementation, you incrementally test everything you write. This increases code quality very much, as you immediately see, where you might have bugs.</p>\n'}]
['https://Stackoverflow.com/questions/1383', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/314/']