From: Perrick P. <pp...@us...> - 2007-03-15 17:55:44
|
Update of /cvsroot/simpletest/simpletest/docs/source/en In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv26040/docs/source/en Added Files: experimental_intro.xml experimental_autorun.xml Log Message: First batch for the 'experimentail' docs. And 'autorun' in particular. --- NEW FILE: experimental_autorun.xml --- <?xml version="1.0"?> <page title="Running the tests, the easy way with autorun" here="Autorunning test cases"> <long_title>[experimental] Running the tests, the easy way with autorun</long_title> <content> <div class="experimental"> Careful : this documentation refers to un-released code. It's only available in CVS. </div> <p> You started with unit testing not so long ago and this is what you came up with... A file <em>test_of_all_modules.php</em> containing : <php><![CDATA[ <?php require_once('simpletest/unit_tester.php'); require_once('simpletest/reporter.php'); $group = new GroupTest(); $group->addTestFile('test_of_module_ship.php'); $group->addTestFile('test_of_module_pay.php'); $group->run(new HtmlReporter()); ?> ]]></php> </p> <p> But now you have a new way of shipping your socks overseas. Easily you just need to add a new file <em>test_of_module_ship_overseas.php</em> to your test runner... Quickly enough, you end up with a lot of file : <php><![CDATA[ <?php require_once('simpletest/unit_tester.php'); require_once('simpletest/reporter.php'); $group = new GroupTest(); $group->addTestFile('test_of_module_ship.php');<strong> $group->addTestFile('test_of_module_ship_overseas.php'); $group->addTestFile('test_of_module_ship_france.php'); $group->addTestFile('test_of_module_ship_uk.php'); $group->addTestFile('test_of_module_ship_us.php'); ...</strong> $group->addTestFile('test_of_module_pay.php'); $group->run(new HtmlReporter()); ?> ]]></php> </p> <p> As you list grows, running the test suite becomes too time- consuming : the tests are actually slowing you down while writing code. </p> <p> <a class="target" name="autorun"><h2>Introducing 'autorun'</h2></a> </p> <p> What we're looking for now is a way to run one test at a time and still be able to run every one of them easily... What if we could just write - in a console for example : <div class="console"> home: /$ <strong>php test_of_module_ship_us.php</strong> </div> and still be able to do : <div class="console"> home: /$ <strong>php test_of_all_modules.php</strong> </div> It's possible now : you just need to add one include at the top of each test case. Your <em>test_of_module_ship_us.php</em> will look like : <php><![CDATA[ <?php<strong> require_once(dirname(__FILE__) . 'simpletest/autorun.php');</strong> class TestUsingParcelForce extends UnitTestCase { function testParcelForceIsFine() { $this->assertTrue(true); } } class TestUsingMyOwnAirplane extends UnitTestCase { function testUsingMyOwnAirplaneOnlyWorksForSmallGifts() { $this->assertFalse(false); } } ?> ]]></php> </p> <p> <a class="target" name="preference"><h2>Setting the prefered runner</h2></a> </p> <p> PHP is mainly for web stuff : I'm guessing your first test platform is a web browser, Firefox, Opera or Safari usually. And SimpleTest comes with a nice HTML interface : it's the one we want to use when running one file. We can tell our <em>test_of_module_ship_us.php</em> to use it by default : <php><![CDATA[ <?php require_once(dirname(__FILE__) . 'simpletest/autorun.php');<strong> SimpleTest :: prefer(new HtmlReporter());</strong> class TestUsingParcelForce extends UnitTestCase { function testParcelForceIsFine() { $this->assertTrue(true); } } class TestUsingMyOwnAirplane extends UnitTestCase { function testUsingMyOwnAirplaneOnlyWorksForSmallGifts() { $this->assertFalse(false); } } ?> ]]></php> </p> <p> We get a nice green bar : <div class="demo"> <h1>GroupTest</h1> <div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">2/2 test cases complete: <strong>2</strong> passes, <strong>0</strong> fails and <strong>0</strong> exceptions.</div> </div> </p> <p> <a class="target" name="autorun-for-suites"><h2>Autorun for test suites</h2></a> </p> <p> So we've managed to get the time spent running the test under control during the coding period. We now want to make sure all the tests still pass, all the time. Or at least after every commit to the SVN (or CVS) trunk. </p> <p> Such process is called <em>continuous integration</em> : Martin Fowler writes really well about this practice <cite>where members of a team integrate their work frequently [...]. Each integration is verified by an automated buid (including test) to detect integration errors as quickly as possible</cite>. So I can just give you the link : <a href="http://www.martinfowler.com/articles/continuousIntegration.html">Continuous Integration</a>. </p> <p> Now our post-commit hook in SVN (or Phing task if you prefer) doesn't need the HTML reporter. We need something useful at the command line : TextReporter to the rescue. Our <em>test_of_all_modules.php</em> becomes : <php><![CDATA[ <?php require_once('simpletest/autorun.php'); <strong> SimpleTest :: prefer(new TextReporter());</strong> class AllTests extends TestSuite { function AllTests() { parent::TestSuite(); $this->addTestFile('test_of_module_ship.php'); $this->addTestFile('test_of_module_ship_overseas.php'); $this->addTestFile('test_of_module_ship_france.php'); $this->addTestFile('test_of_module_ship_uk.php'); $this->addTestFile('test_of_module_ship_us.php'); ... $this->addTestFile('test_of_module_pay.php'); } } ?> ]]></php> </p> <p> The results show up nicely in the console : <div class="console"> home: /$ php test_of_all_modules.php<br /> <strong>grouptest<br /> OK<br /> Test cases run: 10/10, Passes: 37, Failures: 0, Exceptions: 0</strong> </div> </p> </content> <internal> <link>Introducing <a href="#autorun">'autorun'</a>.</link> <link>Setting <a href="#preference">the prefered runner</a>.</link> <link>Autorun for <a href="#autorun-for-suites">test suites</a>.</link> </internal> <external> <link> The <a href="http://junit.sourceforge.net/doc/faq/faq.htm">JUnit FAQ</a> has plenty of useful testing advice. </link> <link> <a href="group_test_tutorial.php">Next</a> is grouping test cases together. </link> <link> You will need the <a href="simple_test.php">SimpleTest testing framework</a> for these examples. </link> </external> <meta> <keywords> software development, php programming, programming php, software development tools, php tutorial, free php scripts, architecture, php resources, mock objects, junit, php testing, unit test, automated php testing, test cases tutorial, explain unit test case, unit test example, unit test </keywords> </meta> </page> --- NEW FILE: experimental_intro.xml --- <?xml version="1.0"?> <page title="Experimental stuff (in CVS only)" here="Experimental stuff"> <long_title>Experimental stuff, found in CVS only</long_title> <content> <section name="intro" title="Why only in CVS"> <p> If a bug is found in SimpleTest, chances are it'll get corrected inside the CVS tree with the corresponding test case : just to make sure the bug doesn't make a come back later on. </p> <p> Also the SimpleTest CVS trunk is usually full of little known experiments with code : new ideas are usually tried out there before a general release. Before it happens, the documentation need to be completed : that's where this section comes into place. You'll find here new features the dev team is happy with : we're looking for comments... </p> <p> The mailing-list is usually the best place to give feedback. Other options includes submitting a bug or a patch directly on the Sourceforge trackers... </p> <p class="experimental"> Note : some of these features may never make to a release or not before a long time ! </p> </section> </content> <external> <link> SimpleTest <a href="http://sourceforge.net/mail/?group_id=76550">mailing-lists' page on SourceForge</a>. </link> <link> SimpleTest <a href="http://sourceforge.net/tracker/?group_id=76550">trackers' page on Sourceforge</a> as well. </link> </external> <meta> <keywords> php unit testing, test integration, documentation, marcus baker, simple test, simpletest documentation, phpunit, pear, experimental, cvs, code experiment, feedback </keywords> </meta> </page> |