<p>I am a web-developer working in PHP. I have some limited experience with using Test Driven Development in C# desktop applications. In that case we used nUnit for the unit testing framework.</p>

<p>I would like to start using TDD in new projects but I'm really not sure where to begin. </p>

<p>What recommendations do you have for a PHP-based unit testing framework and what are some good resources for someone who is pretty new to the TDD concept?</p>

[{'answer_id': 46293, 'author': 'Eric Hogue', 'author_id': 4137, 'author_profile': 'https://Stackoverflow.com/users/4137', 'pm_score': 1, 'selected': False, 'text': '<p>You should look into <a href="http://www.phpunit.de/" rel="nofollow noreferrer">PHPUnit</a>, it looks pretty much like nUnit. </p>\n'}, {'answer_id': 46294, 'author': 'Mark Biek', 'author_id': 305, 'author_profile': 'https://Stackoverflow.com/users/305', 'pm_score': 6, 'selected': True, 'text': '<p>I\'ve used both PHPUnit &amp; <strong><a href="http://simpletest.org/" rel="noreferrer">SimpleTest</a></strong> and I found <strong>SimpleTest</strong> to be easier to use.</p>\n\n<p>As far as TDD goes, I haven\'t had much luck with it in the purest sense.  I think that\'s mainly a time/discipline issue on my part though.</p>\n\n<p>Adding tests after the fact has been somewhat useful but my favorite things to do is use write SimpleTest tests that test for specific bugs that I have to fix.  That makes it very easy to verify that things are actually fixed and stay fixed.</p>\n'}, {'answer_id': 46297, 'author': 'MattBelanger', 'author_id': 655, 'author_profile': 'https://Stackoverflow.com/users/655', 'pm_score': 2, 'selected': False, 'text': "<p>SimpleTest is a great system.  I started out with it about 5 months ago, having never heard of TDD, and SimpleTest is easy to learn but still powerful.  As for resources, I'm currently reading <em>TDD By Example</em> by Kent Beck, and it's good.</p>\n"}, {'answer_id': 46351, 'author': 'Till', 'author_id': 2859, 'author_profile': 'https://Stackoverflow.com/users/2859', 'pm_score': 3, 'selected': False, 'text': '<p>PHPUnit is a standard, but it\'s sometimes also overwhelming, so if you find it too complex, check out <a href="http://qa.php.net/write-test.php" rel="noreferrer">phpt</a> to get you started. It\'s very, very easy to write tests in it. A no brainer for any programmer.</p>\n\n<p>And to answer your TDD question - I am not sure if TDD is widley used in the PHP space. I can see that rapid application development and TDD somewhat clash (strictly IMHO). TDD requires you to have the complete picture of what you build and you write your tests up front and then implement the code to make the test pass.</p>\n\n<p>So for example what we do instead, is to write a lot of tests when we are done. This is not always the best approach because you sometimes end up with bogus tests that pass, but are not really useful but at least it\'s something you can expand on. Internally we continue on tests and basically write a test for each bug we find. This is how it becomes more solid.</p>\n'}, {'answer_id': 46971, 'author': 'Sam McAfee', 'author_id': 577, 'author_profile': 'https://Stackoverflow.com/users/577', 'pm_score': 2, 'selected': False, 'text': '<p>I personally prefer SimpleTest. There is a command line test runner and web-based test runner, and there is even an Eclipse <a href="http://simpletest.sourceforge.net/en/extension_eclipse.html" rel="nofollow noreferrer">plugin</a> to let you run unit tests from the IDE itself. I found the Zend to PHPUnit connection much harder to get working, especially with the debugger.</p>\n\n<p>The way we use SimpleTest in-house is with a <a href="http://www.martinfowler.com/articles/continuousIntegration.html" rel="nofollow noreferrer">continuous integration</a> script that we wrote ourselves. Every time we check in a feature to SVN we include the unit tests. Every hour or so, the CI script runs and calls a command line PHP script that runs all of our unit tests. If any break, I get an email. It\'s been a great way to reduce bugs in our systems.</p>\n\n<p>However, you can just as easily use something like <a href="http://phing.info/trac/" rel="nofollow noreferrer">Phing</a> to run your tests automatically, either on a cron job or with an SVN check-in hook.</p>\n\n<p>In fact, if you want to contact me directly for further help, you can get to me through my profile info on SO. I\'d love to help you out.</p>\n'}, {'answer_id': 50716, 'author': 'Mike H', 'author_id': 4563, 'author_profile': 'https://Stackoverflow.com/users/4563', 'pm_score': 4, 'selected': False, 'text': '<p>I highly recommend <a href="https://rads.stackoverflow.com/amzn/click/com/0321146530" rel="noreferrer" rel="nofollow noreferrer">Test-Driven Development by Kent Beck (ISBN-10: 0321146530)</a>. It wasn\'t written specifically for PHP, but the concepts are there and should be easily translatable to PHP.</p>\n'}, {'answer_id': 9474298, 'author': 'Davert', 'author_id': 1168291, 'author_profile': 'https://Stackoverflow.com/users/1168291', 'pm_score': 1, 'selected': False, 'text': '<p>Another modern tool you should look it is <a href="http://codeception.com/02-15-2012/unit-testing.html" rel="nofollow">Codeception</a>. It is much simplier then PHPUnit and incorporates scenario-driven approach, which is quite useful for generating documentation from tests.</p>\n'}, {'answer_id': 51050858, 'author': 'Aman Rastogi', 'author_id': 9996558, 'author_profile': 'https://Stackoverflow.com/users/9996558', 'pm_score': 0, 'selected': False, 'text': '<p>Test driven development is an approach where tests are always written before code. \nYou should learn to <a href="https://phpunit.de/" rel="nofollow noreferrer">PHPUNIT</a> first in order to start TDD Development. Then while making your function you should always think how function can fail and write test case in phpunit and in the end you should write code in order to pass your test. Its will be a new approach so it will be little difficult in the beginning but once you get use to it, you will find it very useful specially for after development bugs and coding style. You can go through this <a href="http://vihasverma.blogspot.com/" rel="nofollow noreferrer">Step By Step</a> guide for understanding this concept. </p>\n\n<p>Always Remember if test are written after development they are useless. So TDD is must if you are thinking to write unit tesst </p>\n'}]
['https://Stackoverflow.com/questions/46276', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3238/']