<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cakebaker &#187; simpletest</title>
	<atom:link href="http://cakebaker.42dh.com/tags/simpletest/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 20 Dec 2011 15:29:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Skipping test cases</title>
		<link>http://cakebaker.42dh.com/2008/06/23/skipping-test-cases/</link>
		<comments>http://cakebaker.42dh.com/2008/06/23/skipping-test-cases/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 15:19:02 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[simpletest]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=616</guid>
		<description><![CDATA[Some days ago Tim Koschützki showed in an article how you can execute only some specific test methods in (SimpleTest-based) unit tests by overriding the getTests() method. Sometimes you not only want to skip some test methods but an entire test case. For example, the tests of the MySQL datasource test case can only be [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago <a href="http://debuggable.com/tim">Tim Koschützki</a> showed in an <a href="http://debuggable.com/posts/how-to-execute-only-specific-test-methods-in-cakephp-unit-tests:4858fa7b-7194-4652-9c7f-47784834cda3">article</a> how you can execute only some specific test methods in (<a href="http://simpletest.org">SimpleTest</a>-based) unit tests by overriding the getTests() method.</p>
<p>Sometimes you not only want to skip some test methods but an entire test case. For example, the tests of the MySQL datasource test case can only be executed successfully if there is a MySQL database (or else you will get many errors). What do you do in such a case? </p>
<p>You could override the getTests() method and simply return an empty array if there is no MySQL database available:</p>
<pre>
public function getTests() {
    if (!$this-&gt;isMySQLAvailable()) {
        return array();
    }

    return parent::getTests();
}
</pre>
<p>This works, but it is rather a theoretical approach. Usually you override the method which was designed for this purpose: skip. In this method you use then either the skipIf() or skipUnless() method to determine whether the test case should be skipped. So we can rewrite the example from above in the following way:</p>
<pre>
public function skip() {
    $this-&gt;skipUnless($this-&gt;isMySQLAvailable());
    // $this-&gt;skipIf(!$this-&gt;isMySQLAvailable()); has the same effect
}
</pre>
<p>If you now run the test case, and you don&#8217;t have a MySQL database, you will get informed that the respective test case has been skipped.</p>
<p>Happy testing!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/06/23/skipping-test-cases/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Testing with partial mock objects</title>
		<link>http://cakebaker.42dh.com/2007/12/04/testing-with-partial-mock-objects/</link>
		<comments>http://cakebaker.42dh.com/2007/12/04/testing-with-partial-mock-objects/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 16:28:02 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[simpletest]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/12/04/testing-with-partial-mock-objects/</guid>
		<description><![CDATA[When testing your models with unit tests you probably encounter the &#8220;problem&#8221; of slow test execution due to all those database accesses. And that&#8217;s bad. You want the test execution to be fast so you can run the tests often. What can you do to avoid the database accesses? Well, the SimpleTest framework &#8212; the [...]]]></description>
			<content:encoded><![CDATA[<p>When testing your models with unit tests you probably encounter the &#8220;problem&#8221; of slow test execution due to all those database accesses. And that&#8217;s bad. You want the test execution to be fast so you can run the tests often. What can you do to avoid the database accesses? </p>
<p>Well, the <a href="http://simpletest.org">SimpleTest</a> framework &#8212; the testing framework used by CakePHP &#8212; provides a feature called &#8220;partial mocks&#8221;. With this feature it is possible to fake certain methods of a class, i.e. we can mock those methods which access the database.  </p>
<p>Let&#8217;s have a look at an example. </p>
<p>We assume we want to test a method which checks whether the provided tags are in the database, and returns then those tags which are not yet in the database. </p>
<p>As we use findAll() to retrieve the tags, we have to mock this method. We can do it with the following snippet:</p>
<pre>
Mock::generatePartial('Tag', 'MockTag', array('findAll'));
</pre>
<p>The first parameter of Mock::generatePartial() specifies the class we want to mock, the second parameter defines the name of the mocked class, and the last parameter defines the methods we want to mock. </p>
<p>In the test we will now use the MockTag class instead of the Tag class. It is identical to the Tag class (technically it is a subclass of it), with the difference that the implementation of findAll() doesn&#8217;t &#8220;exist&#8221; anymore. With setReturnValue() we can now specify what findAll() should return when called. Below you find the test code, it should be self-explanatory (if not, please leave a comment):</p>
<pre>
Mock::generatePartial('Tag', 'MockTag', array('findAll'));

class TagTest extends CakeTestCase {
    function testExtractNewTags() {
        $existingTags = array(0 =&gt; array('Tag' =&gt; array('name' =&gt; 'tagA')),
			                   1 =&gt; array('Tag' =&gt; array('name' =&gt; 'tagB')));

        $mock = new MockTag($this);
        $mock-&gt;setReturnValue('findAll', $existingTags);

        $newTags = $mock-&gt;extractNewTags(array('tagA', 'tagB'));
        $this-&gt;assertIdentical(array(), $newTags);

        $newTags = $mock-&gt;extractNewTags(array('tagA', 'tagC', 'tagD'));
        $this-&gt;assertEqual(2, count($newTags));
        $this-&gt;assertEqual('tagC', $newTags[0]);
        $this-&gt;assertEqual('tagD', $newTags[1]);
    }
}
</pre>
<p>That&#8217;s only one simple example of what you can do with partial mock objects. For more see the <a href="http://simpletest.org/en/partial_mocks_documentation.html">SimpleTest documentation</a>. </p>
<p>Happy testing :)</p>
<p>Update 2007-12-08: Something I forgot to mention is that you have to include the file mock_objects.php to make it work. You can do it with </p>
<pre>
vendor('simpletest'.DS.'mock_objects');
</pre>
<p>at the top of your test case file. </p>
<p>Thanks to <a href="http://www.3-threes.com/">Zach Cox</a> for asking me this by email!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/12/04/testing-with-partial-mock-objects/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to use the official CakePHP test suite</title>
		<link>http://cakebaker.42dh.com/2007/03/23/how-to-use-the-official-cakephp-test-suite/</link>
		<comments>http://cakebaker.42dh.com/2007/03/23/how-to-use-the-official-cakephp-test-suite/#comments</comments>
		<pubDate>Fri, 23 Mar 2007 14:55:39 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[simpletest]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/03/23/how-to-use-the-official-cakephp-test-suite/</guid>
		<description><![CDATA[If you are using CakePHP 1.2 you probably noticed the folders /app/tests and /cake/tests. They are part of the official CakePHP test suite which comes with Cake. Before you can use it, you have to download SimpleTest, the testing framework used by the test suite. Extract the package to your vendors folder and you are [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using CakePHP 1.2 you probably noticed the folders /app/tests and /cake/tests. They are part of the official CakePHP test suite which comes with Cake.</p>
<p>Before you can use it, you have to download <a href="http://simpletest.org">SimpleTest</a>, the testing framework used by the test suite. Extract the package to your vendors folder and you are ready to execute tests. (If you have an advanced setup you also have to change the value of CAKE_CORE_INCLUDE_PATH in app/webroot/test.php)</p>
<p>To execute tests you have to go to example.com/test.php and you will see the following page:</p>
<p><img src='http://cakebaker.42dh.com/wp-content/uploads/2007/03/test_suite.png' alt='Testsuite' /></p>
<p>There you can select whether you want to execute the core tests or your own application-specific tests. These application-specific tests must be placed in the respective folders in app/tests/cases resp. in app/tests/groups if they are group tests. The file names of the tests must end with &#8220;.test.php&#8221; (e.g. &#8220;user.test.php&#8221; for the user model test) respectively &#8220;.group.php&#8221; (e.g. &#8220;helpers.group.php&#8221; for a group test of all helpers). It&#8217;s imho a bit illogical, as everywhere else in the framework an underscore is used to separate the name parts. As usual in Cake, the class names are camel-cased, so the class names will be &#8220;UserTest&#8221; and &#8220;HelpersGroup&#8221;. Apart from those conventions the tests are &#8220;normal&#8221; SimpleTest tests, there is no magic (yet). You can find many real-world examples of such tests in /cake/tests.</p>
<p>Personally, I still prefer my <a href="http://cakebaker.42dh.com/2006/12/18/testing-with-cakephp-12-a-preview/">own test suite</a>, even though it requires a bit more configuration work.</p>
<p>Happy testing :)</p>
<p>Update (2007-04-07): In the meantime fixtures have been introduced. The usage of them is described in <a href="http://bakery.cakephp.org/articles/mariano/2007/04/13/testing-models-with-cakephp-1-2-test-suite">&#8220;Testing Models with CakePHP 1.2 test suite&#8221;</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/03/23/how-to-use-the-official-cakephp-test-suite/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How to use Selenium with SimpleTest</title>
		<link>http://cakebaker.42dh.com/2006/11/16/how-to-use-selenium-with-simpletest/</link>
		<comments>http://cakebaker.42dh.com/2006/11/16/how-to-use-selenium-with-simpletest/#comments</comments>
		<pubDate>Thu, 16 Nov 2006 09:39:52 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[simpletest]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/11/16/how-to-use-selenium-with-simpletest/</guid>
		<description><![CDATA[Up to now there was no PHP support for Selenium Remote Control, i.e. you couldn&#8217;t integrate your Selenium tests with a testing framework like SimpleTest. On PEAR there is now a package called Testing_Selenium which makes it easy to use PHP and Selenium Remote Control together. To use them you need PHP5 and a JRE [...]]]></description>
			<content:encoded><![CDATA[<p>Up to now there was no PHP support for <a href="http://www.openqa.org/selenium-rc/">Selenium Remote Control</a>, i.e. you couldn&#8217;t integrate your Selenium tests with a testing framework like <a href="http://www.lastcraft.com/simple_test.php">SimpleTest</a>. On PEAR there is now a package called <a href="http://pear.php.net/package/Testing_Selenium">Testing_Selenium</a> which makes it easy to use PHP and Selenium Remote Control together. To use them you need PHP5 and a JRE (Java Runtime Environment) version 1.5 or higher. The installation itself is simple. Here the installation instructions for CakePHP:</p>
<ul>
<li><a href="http://pear.php.net/package/Testing_Selenium/download">Download</a> the package</li>
<li>Put Selenium.php to your &#8220;vendors&#8221; folder</li>
<li>Create a folder &#8220;Testing&#8221; in your &#8220;vendors&#8221; folder</li>
<li>Put the &#8220;Selenium&#8221; folder from the archive to the &#8220;Testing&#8221; folder</li>
<li>Put selenium-server.jar to a folder of your choice</li>
</ul>
<p>Ok, as the installation is done, let&#8217;s write a simple testcase. We want to verify that the title of the cake website is correct.</p>
<pre>
vendor('Selenium');

class SeleniumTest extends UnitTestCase
{
    function setUp()
    {
        $this-&gt;selenium = new Testing_Selenium("*firefox /usr/lib/firefox/firefox-bin", "http://cakephp.org");
        $result = $this-&gt;selenium-&gt;start();
    }

    function tearDown()
    {
        $this-&gt;selenium-&gt;stop();
    }

    function testCakePHPTitle()
    {
        $this-&gt;selenium-&gt;open("/");
        $this-&gt;assertEqual('CakePHP : the rapid development php framework', $this-&gt;selenium-&gt;getTitle());
    }
}
</pre>
<p>What does this do? In the setUp() function we start a Firefox browser (we could also use a different browser). With that browser we open in the test function the cake homepage and get the page title. And in tearDown() we close the browser.</p>
<p>Before we can run this test, we have to start the Selenium server with:</p>
<pre>
java -jar selenium-server.jar
</pre>
<p>Now, we should get a green bar when we run the test. </p>
<p>Happy testing :)</p>
<p>Update (2006-11-29): If you don&#8217;t want to put the exception class to the vendors folder, you can replace in Selenium.php </p>
<pre>
require_once 'Testing/Selenium/Exception.php';
</pre>
<p>with</p>
<pre>
class Testing_Selenium_Exception extends Exception {}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/11/16/how-to-use-selenium-with-simpletest/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

