<?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>code-diesel &#187; testing</title>
	<atom:link href="http://www.codediesel.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Measuring user effectiveness with the Apdex metric</title>
		<link>http://www.codediesel.com/software/measuring-user-effectiveness-with-the-apdex-metric/</link>
		<comments>http://www.codediesel.com/software/measuring-user-effectiveness-with-the-apdex-metric/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 14:20:33 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[apdex]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2727</guid>
		<description><![CDATA[Creating a business application is one thing, measuring user-satisfaction another. Most software houses in recent years have woken up to the importance of user-facing metrics, the knowledge that user satisfaction regarding software application performance is an integral part of business success. But the problem in application performance measurement is that there are too many metrics [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a business application is one thing, measuring user-satisfaction another. Most software houses in recent years have woken up to the importance of user-facing metrics, the knowledge that user satisfaction regarding software application performance is an integral part of business success. But the problem in application performance measurement is that there are too many metrics and measurements which in the end adds nothing of real value to the performance reports. What most people need is a metric that is easy to calculate and interpret. Apdex is one such metric.<br />
<span id="more-2727"></span></p>
<h4>Apdex: Measuring user effectiveness</h4>
<p>Apdex (Application Performance Index) is an open measurement standard developed by a  group of companies. It is a numerical measure of user satisfaction regarding performance of web or desktop applications. It enables management to gain insights about user satisfaction with respect to the developed application. </p>
<p>Apdex converts multiple  measurements into a single number on a scale of 0 to 1 (0 = no users satisfied, 1 = all users satisfied). This metric can be applied to any source of end-user performance measurements that gathers timing data.</p>
<p>The index is based on three areas of application responsiveness, we will see this in the context of web applications. The three areas are partitioned by two time limits, <strong>T</strong> and <strong>F</strong>. <strong>T</strong> (satisfied-tolerating<br />
boundary) represents the base time limit (in seconds) below which the application is responsive; and <strong>F</strong> represents the maximum limit after which the application response drops considerably and the user may close the application or navigate to another site. F is taken as (4xT) or four times T.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/10/apdex3.gif"><img  style="border:none;"  src="http://www.codediesel.com/wp-content/uploads/2010/10/apdex3.gif" alt="" title="apdex3" width="514" height="194" class="aligncenter size-full wp-image-2731" /></a></p>
<p>■ <strong>Satisfied</strong>—The user is completely productive. This represents the time value <strong>T</strong> below which<br />
users are not impeded by application response time. For e.g when a web page loads in less than 3 seconds.</p>
<p>■ <strong>Tolerating</strong>— With response time greater than <strong>T</strong> the user starts noticing the performance lag but continues the process. E.g. when the page takes around 10-15 seconds to completely load.</p>
<p>■ <strong>Frustrated</strong>—Performance with a response time greater than <strong>F</strong> seconds leads to frustration and the user usually navigates away from the site.</p>
<p>So if we need to measure the Apdex score for a 75 page enterprise web application, we have to initially set the target times <strong>T</strong> and <strong>F</strong> around which our three measurements will be based.</p>
<p>Lets set T to 3 seconds and F to 12 seconds. After measuring the load time of the 75 pages we find that 28 pages load in less than 3 seconds, 40 page load between T and F seconds, and the remaining load in more than F seconds. In short:</p>
<p>Load time of 28 pages <= T<br />
T < Load time of 40 pages <= F<br />
Load time of 7 pages > F</p>
<p>We can then calculate the Apdex score using the following formula:</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/10/apdex11.gif"><img  style="border:none;" src="http://www.codediesel.com/wp-content/uploads/2010/10/apdex11.gif" alt="" title="apdex1" width="324" height="82" class="aligncenter size-full wp-image-2733" /></a></p>
<p>Which in our case will give a score of <strong>0.64</strong>:</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/10/apdex22.gif"><img  style="border:none;"  src="http://www.codediesel.com/wp-content/uploads/2010/10/apdex22.gif" alt="" title="apdex2" width="191" height="69" class="aligncenter size-full wp-image-2735" /></a></p>
<p>The score gives a value of &#8217;1&#8242; when all the users are satisfied with the application performance, a &#8217;0&#8242; when no one is satisfied and &#8217;0.5&#8242; when all the users are tolerating the application performance. For other variations the score can range  between 0 &#8211; 1.</p>
<h4>Advantages of Apdex</h4>
<p>The main advantage of the metric is that it provides a single score that lets the IT manager easily compare performace between different applications or different versions of the same applications. In the context of web applications a IT manager can easily compare the Apdex score before and after optimizing a web application.</p>
<p><strong>References:</strong><br />
<a href="http://en.wikipedia.org/wiki/Apdex" rel="nofollow" >http://en.wikipedia.org/wiki/Apdex</a><br />
<a href="http://www.apdex.org/index.html" rel="nofollow" >http://www.apdex.org/index.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/software/measuring-user-effectiveness-with-the-apdex-metric/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging and tracing PHP5 applications</title>
		<link>http://www.codediesel.com/php/debugging-and-tracing-php5-applications-on-production-servers/</link>
		<comments>http://www.codediesel.com/php/debugging-and-tracing-php5-applications-on-production-servers/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 08:37:40 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[debugging]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2715</guid>
		<description><![CDATA[debugConsole is a tool for debugging and tracing PHP5 applications on production servers without compromising the live-traffic. With PHP functions you can inspect variables, watch changes in variables over the whole runtime, measure partial runtimes, set checkpoints and write logfiles. debugConsole also replaces the PHP error-handling so that notices, warnings and other errors are also [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.debugconsole.de/" rel="nofollow" target="_blank" >debugConsole</a> is a tool for debugging and tracing PHP5 applications on production servers without compromising the live-traffic.</p>
<p>With PHP functions you can inspect variables, watch changes in variables over the whole runtime, measure partial runtimes, set checkpoints and write logfiles. debugConsole also replaces the PHP error-handling so that notices, warnings and other errors are also shown in a popup, instead of displaying them in the application to be debugged.<br />
<span id="more-2715"></span><br />
IP-based access restrictions can be defined in the configuration file so that the popup only opens for developers from that IP and not for visitors. After finishing work, the popup can simply be switched off.</p>
<p>Below is a simple example, and its output:</p>

<div class="wp_codebox"><table><tr id="p27152"><td class="code" id="p2715code2"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/* load debugConsole functionality */</span>
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'debugConsole/debugConsole.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* test variable debugging */</span>
<span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hello World!'</span><span style="color: #339933;">;</span>
dc_dump<span style="color: #009900;">&#40;</span><span style="color: #000088;">$foo</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$foo wants to say something:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* test variable debugging again */</span>
<span style="color: #000088;">$bar</span> <span style="color: #339933;">=</span> <span style="color:#800080;">42.0</span><span style="color: #339933;">;</span>
dc_dump<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bar</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$bar tells us the meaning of life:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* test array debugging */</span>
<span style="color: #000088;">$foobar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'foo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$foo</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'bar'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$bar</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dc_dump<span style="color: #009900;">&#40;</span><span style="color: #000088;">$foobar</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$foobar is a neat array!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a href="http://www.codediesel.com/wp-content/uploads/2010/10/debug-console.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/10/debug-console.gif" alt="" title="debug-console" width="290" height="332" class="alignleft size-full wp-image-2718" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/debugging-and-tracing-php5-applications-on-production-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importance of logging in web development</title>
		<link>http://www.codediesel.com/software/logging-in-web-development/</link>
		<comments>http://www.codediesel.com/software/logging-in-web-development/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 14:32:19 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[logs]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/sql/logging-for-your-sanity/</guid>
		<description><![CDATA[Software development is an exercise in managing complexity, and the more tools and methods we have at our disposal the easier it gets. One of my favorites is logging – recording important code execution points that I think are important, especially during debugging. Whenever developing functions or class methods I make it a point to [...]]]></description>
			<content:encoded><![CDATA[<p>Software development is an exercise in managing complexity, and the more tools and methods we have at our disposal the easier it gets. One of my favorites is logging – recording important code execution points that I think are important, especially during debugging. Whenever developing functions or class methods I make it a point to add logging capabilities to the same.  Logging helps one to quickly tracks bugs and evaluate the health of the system under development.<br />
<span id="more-2710"></span><br />
But what information does one log and what does one keep out. This usually depends on what kind of application you are developing. While developing database intensive applications I prefer to log every query execution state – the whole CRUD things. This helps me to quickly pinpoint any query errors and the sequence in which the queries are run. </p>
<p>Take an example class method addUser() shown below. When the query is executed the result is logged in a file with the function name and a user_id or a serialized error string in case of an error. Whenever the application is in a testing phase, the error logs are an immense help in diagnosing error points. This is better than a splattering of <em>print_r</em> statements all around the code.</p>

<div class="wp_codebox"><table><tr id="p27106"><td class="code" id="p2710code6"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LOG&quot;</span><span style="color: #339933;">,</span>  <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** Add new user to the system
 *
 *  @param array $user_data
 *  @return boolean
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span>  addUser<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_data</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$sql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">LOG</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$err_string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_log<span style="color: #339933;">-&gt;</span><span style="color: #004000;">LogError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;addUserd | error | &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$err_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">LOG</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_log<span style="color: #339933;">-&gt;</span><span style="color: #004000;">LogInfo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;addUser| no. | &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The contents of a sample log file are shown below.</p>

<div class="wp_codebox"><table><tr id="p27107"><td class="code" id="p2710code7"><pre class="text" style="font-family:monospace;">2010-07-31 4:52:58 - INFO  | addUser | no. | h1280551978 
2010-07-31 4:53:04 - INFO  | user edit | no. | 1 
2010-07-31 4:53:06 - INFO  | user edit | no. | 1 
2010-07-31 4:53:07 - INFO  | addUser| no. | 1 
2010-07-31 4:53:09 - ERROR | addUser| error | 
a:3:{i:0;s:5:&quot;23&quot;;i:1;i:148;i:2;s:30:&quot;Column 'fileno' cannot be null&quot;;}</pre></td></tr></table></div>

<p>Although logs can add some overhead to your code, it is a small price to pay for the benefits it provides. And if you do not want the logging feature you can easily disable it by setting the <em>LOG</em> constant to &#8216;false&#8217; in the above code.</p>
<h4>Which logger to use</h4>
<p>Although there a variety of libraries, I prefer <a href="http://github.com/katzgrau/KLogger" rel="nofollow" target="_blank" >KLogger</a> as it has a small footprint and is easy to use. Other more advanced contender is <a href="http://logging.apache.org/log4php/" rel="nofollow" target="_blank" >Log4PHP</a>, a PHP port of log4j, a Java logger. <a href="http://framework.zend.com/manual/en/zend.log.html" rel="nofollow" target="_blank" >Zend_Log</a> also looks nice but I am yet to give it a try.</p>
<h4>Analyzing logs</h4>
<p>For big, frequently used applications, log files can quickly get quite huge. The easy way to analyze them is to use GUI tools like <a href="http://www.logmx.com/" rel="nofollow" target="_blank" >LogMX</a> and <a href="http://logging.apache.org/chainsaw/index.html" rel="nofollow" target="_blank" >Apache Chainsaw</a>. But if you just need to get some simple statistics from your logs, you could use the trusty old <em>grep</em> and other *nix utilities. For example to count the total error lines having the string &#8216;mysql&#8217; you could use the following code.</p>

<div class="wp_codebox"><table><tr id="p27108"><td class="code" id="p2710code8"><pre class="unix" style="font-family:monospace;">$ grep 'ERROR ' activity.log | grep 'mysql' | wc -l</pre></td></tr></table></div>

<p>The advantage of scripts over GUI tools is that you can automatically process them using CRON jobs, e.g &#8211;  emailing the admin if some particular type of errors in a log reaches some critical limit.</p>
<p>In conclusion, logs are one of the simplest ways of keeping track of your code problems or to check the execution sequence of your statements. This can be immensely helpful during development and for tracking down bugs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/software/logging-in-web-development/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Selenium IDE: Pattern matching</title>
		<link>http://www.codediesel.com/testing/selenium-ide-pattern-matching/</link>
		<comments>http://www.codediesel.com/testing/selenium-ide-pattern-matching/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 04:01:01 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2692</guid>
		<description><![CDATA[Patterns are bread and butter of Selenium tests. Many commands in Selenium take the pattern parameter. They enable you to match various content types on a web page – links, text, elements. There are chiefly three type of patterns you can use in your tests: globs, exact and regular expressions. Globs Globs or the verb [...]]]></description>
			<content:encoded><![CDATA[<p>Patterns are bread and butter of Selenium tests. Many commands in Selenium take the pattern parameter. They enable you to match various content types on a web page – links, text, elements. There are chiefly three type of patterns you can use in your tests: <em>globs</em>, <em>exact</em> and <em>regular expressions</em>.<br />
<span id="more-2692"></span></p>
<h4>Globs</h4>
<p><strong>Globs</strong> or the verb <strong>Globbing</strong> is familiar to most people who have ever used file matching patterns. If you have ever searched for a file in Linux or DOS using a line like <em>*.exe</em> or <em>photos*</em>, then you have used globs.  But globbing in Selenium is not as rich as the one in Linux – it supports only three  special characters: <strong>*</strong>, <strong>?</strong> and <strong>[ ]</strong>.</p>
<p> <strong>*</strong> matches any number of characters, by any we mean ‘nothing’, ‘a single character’ or ‘many characters’.</p>
<p><strong>?</strong> , matches a single character.</p>
<p><strong>[ ]</strong> , called a character class, lets you match any single character found within the brackets. e.g</p>
<p><strong>[0-9]</strong> matches any digit<br />
<strong>[a-zA-Z]</strong> matches any alphabet, regardless of case</p>
<p>To specify a glob in a selenium command, prefix the pattern with the <em>glob:</em> string. For example if you would like to search for the texts <em>color</em> or <em>colour</em> then you can use the <em>colo*r</em> glob as shown below.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyTextPresent</td>
<td>glob: colo*r</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>However you are free to eliminate the <em>glob:</em> prefix and only specify the text pattern because globbing patterns are the default in Selenium.</p>
<h4>Regular Expression patterns</h4>
<p>Of the three type of patterns, Regular Expressions are the one that are the most useful. Selenium supports the complete set of RegEx patterns that Javascript supports. So now you are not limited by the *,? And [] globbing patterns. To use RegEx patterns you need to prefix each RegEx with either <em>regexp:</em> or <em>regexpi:</em>, the latter being case-insensitive.</p>
<p>For example the following will test if a input field with the id &#8216;name&#8217; contains the string &#8216;javascript&#8217;, &#8216;JavaScript&#8217; or &#8216;Javascript&#8217;.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyValue</td>
<td>id=name</td>
<td>regexp:[Jj]ava([Ss]cript)</td>
</tr>
</tbody>
</table>
<p>Below are a few common regular expression patterns:</p>
<p><strong>regexp:(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d</strong><br />
:match a date in &#8216;mm/dd/yyyy&#8217; format with any of the &#8216;-&#8217;, &#8216;/&#8217;, &#8216;.&#8217;  as separators.</p>
<p><strong>regexpi:^[A-Z0-9+_.-]+@[A-Z0-9.-]+$</strong><br />
:match a generic email address.</p>
<p><strong>regexp:^[0-9]{5}(?:-[0-9]{4})?$</strong><br />
:match a ZIP code (U.S. postal code), allowing both the five-digit and nine-digit (ZIP + 4) formats.</p>
<p><strong>regexp:^(?!000|666)(?:[0-6][0-9]{2}|7(?:[0-6][0-9]|7[0-2]))-?(?!00)[0-9]{2}-(?!0000)[0-9]{4}$</strong><br />
:match U.S Social Security numbers in the in the AAA-GG-SSSS format.</p>
<p><strong>regexp:^(https?|ftp|file)://.+$</strong><br />
:match almost any url.</p>
<p></strong><br />
<h4>Exact Patterns</h4>
<p>Patterns with the prefix &#8216;exact:&#8217; will match the given text as it is.  For example if you give the search pattern as below, then it will match a glob pattern &#8216;*&#8217; or &#8216;*.java&#8217;.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyValue</td>
<td>glob: *.java</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>But if you want an exact match with the value string, i.e without the glob operator doing its work, you use the &#8216;exact&#8217; pattern as below. In this example the &#8216;*&#8217; (asterisk) will work as a normal character rather then a pattern-matching wildcard character.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyValue</td>
<td>exact: *.java</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>In conclusion the <em>glob:</em> and the <em>exact:</em> pattern are the subsets of the Regular Expression pattern matcher. Everything you can do with glob: or exact: you can accomplish with RegExp.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/testing/selenium-ide-pattern-matching/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Generating random data on the client side</title>
		<link>http://www.codediesel.com/data/generating-random-data-on-the-client-side/</link>
		<comments>http://www.codediesel.com/data/generating-random-data-on-the-client-side/#comments</comments>
		<pubDate>Fri, 21 May 2010 10:07:31 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2658</guid>
		<description><![CDATA[Automatically creating fake or sample data is a frequent requirement for front-end web developers. Although usually not tedious, there are times when you need to quickly and automatically generate structured data for your html forms or CMS systems for testing purposes. Faker.js is a JavaScript implementation inspired by Benjamin Curtis&#8217;s Ruby Gem Faker and Perl&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Automatically creating fake or sample data is a frequent requirement for front-end web developers. Although usually not tedious, there are times when you need to quickly and automatically generate structured data for your html forms or CMS systems for testing purposes.</p>
<p><a href="http://github.com/Marak/Faker.js" rel="nofollow" target="_blank" >Faker.js</a> is a JavaScript implementation inspired by Benjamin Curtis&#8217;s Ruby Gem <a href="http://faker.rubyforge.org/" rel="nofollow" >Faker</a> and Perl&#8217;s <a href="http://search.cpan.org/~jasonk/Data-Faker-0.07/lib/Data/Faker.pm" rel="nofollow" >Data::Faker</a> that lets you generate commonly required data quickly. You can check the <a href="http://maraksquires.com/Faker.js/" rel="nofollow" >demo page</a> to get an idea.<br />
<span id="more-2658"></span></p>
<h4>Getting Fake.js</h4>
<p>You can download the library form <a href="http://github.com/Marak/Faker.js" rel="nofollow" >github</a> and include in your pages where you need to generate the data.</p>

<div class="wp_codebox"><table><tr id="p265817"><td class="code" id="p2658code17"><pre class="javascript" style="font-family:monospace;">..
<span style="color: #339933;">&lt;</span>script src <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Faker/Faker.js&quot;</span> type <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
..</pre></td></tr></table></div>

<h4>Generating fake data</h4>
<p>The API is divided into various sections as show below:</p>

<div class="wp_codebox"><table><tr id="p265818"><td class="code" id="p2658code18"><pre class="text" style="font-family:monospace;"># Name
    * findName
# Address
    * zipCode
    * city
    * streetName
    * streetAddress
    * secondaryAddress
    * ukCounty
    * ukCountry
# PhoneNumber
    * phoneNumber
# Internet
    * email
    * userName
    * domainName
    * domainWord
...</pre></td></tr></table></div>

<p>So if you need to generate a random email address or a zip code you could do it like this:</p>

<div class="wp_codebox"><table><tr id="p265819"><td class="code" id="p2658code19"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> randomEmail <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Internet</span>.<span style="color: #660066;">email</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> randomZip <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Address</span>.<span style="color: #660066;">zipCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Some sample API methods are shown below, but there are more of them which you can find <a href="http://github.com/Marak/Faker.js" rel="nofollow" target="_blank" >here</a> in the API section.</p>

<div class="wp_codebox"><table><tr id="p265820"><td class="code" id="p2658code20"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> longParagraph <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Lorem</span>.<span style="color: #660066;">paragraphs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> singleSentence <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Lorem</span>.<span style="color: #660066;">sentence</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> companyName<span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Company</span>.<span style="color: #660066;">companyName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> catchPhrase <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Company</span>.<span style="color: #660066;">catchPhrase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>One of the interesting methods is &#8216; Faker.Company.catchPhrase()&#8217;, which generates catchy technological phrases. A kind of a tag line generator for your new multi-million dollar company <img src='http://www.codediesel.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . A sample output is shown below.</p>

<div class="wp_codebox"><table><tr id="p265821"><td class="code" id="p2658code21"><pre class="text" style="font-family:monospace;">Stand-alone 5th generation utilisation
Ergonomic explicit focus group
Horizontal human-resource solution
Automated contextually-based knowledge base
Distributed multi-state encoding
Extended zero administration interface
Proactive coherent productivity
Streamlined national approach
Total transitional algorithm
Stand-alone fault-tolerant moderator</pre></td></tr></table></div>

<p>The API also includes several helper methods that lets you create bulk fake data using the single API methods. For example you can generate complete user information templates cards by using a single helper method <span class="method">&#8216;Faker.Helpers.userCard()&#8217;</span>. A sample run is shown below:</p>

<div class="wp_codebox"><table><tr id="p265822"><td class="code" id="p2658code22"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">name</span><span style="color: #339933;">:</span> Blair Nikolaus
username<span style="color: #339933;">:</span> Fernando_Olson
email<span style="color: #339933;">:</span> Jacklyn_Brekke<span style="color: #339933;">@</span>aurore.<span style="color: #000066;">name</span>
address<span style="color: #339933;">:</span>street<span style="color: #339933;">:</span> Kozey Meadow
suite<span style="color: #339933;">:</span> Apt. <span style="color: #CC0000;">664</span>
city<span style="color: #339933;">:</span> Felipastad
zipcode<span style="color: #339933;">:</span> <span style="color: #CC0000;">88071</span>
&nbsp;
phone<span style="color: #339933;">:</span> 571.540.8605 x136
website<span style="color: #339933;">:</span> reba.<span style="color: #660066;">co</span>.<span style="color: #660066;">uk</span>
company<span style="color: #339933;">:</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> Kuhic and Sons
catchPhrase<span style="color: #339933;">:</span> Integrated solution<span style="color: #339933;">-</span>oriented Graphical User Interface
bs<span style="color: #339933;">:</span> seize scalable web services</pre></td></tr></table></div>

<p>The &#8216;Faker.Helpers.userCard()&#8217; method returns a nested object, so you will need to recursively traverse the object to extract the data. A simple function to do the same is given below:</p>

<div class="wp_codebox"><table><tr id="p265823"><td class="code" id="p2658code23"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">// Recursively traverse a nested Javascript object and return it.</span>
<span style="color: #003366; font-weight: bold;">function</span> printObj<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> prop<span style="color: #339933;">,</span> res <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>prop <span style="color: #000066; font-weight: bold;">in</span> obj<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> obj<span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'object'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        res <span style="color: #339933;">+=</span> prop <span style="color: #339933;">+</span> <span style="color: #3366CC;">':'</span> <span style="color: #339933;">+</span> printObj<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
        res <span style="color: #339933;">+=</span> prop <span style="color: #339933;">+</span> <span style="color: #3366CC;">': '</span> <span style="color: #339933;">+</span> obj<span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
   <span style="color: #000066; font-weight: bold;">return</span> res<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>So now you can do something like this:</p>

<div class="wp_codebox"><table><tr id="p265824"><td class="code" id="p2658code24"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Helpers</span>.<span style="color: #660066;">userCard</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> printObj<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...</pre></td></tr></table></div>

<h4>Another Randomizer library</h4>
<p><a href="http://code.google.com/p/clubajax/source/browse/" rel="nofollow" target="_blank" >Club AJAX Mock Data Randomizer</a> library is another library that lets you generate random data quickly. This library lets you generate random dates, colors, boolean values which is lacking in the Faker library. Check a simple <a href="http://www.codediesel.com/data/scripts/random/index.html">demo</a> using this library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/generating-random-data-on-the-client-side/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding custom commands to Selenium</title>
		<link>http://www.codediesel.com/testing/adding-custom-commands-to-the-selenium-ide/</link>
		<comments>http://www.codediesel.com/testing/adding-custom-commands-to-the-selenium-ide/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 09:44:35 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/sql/extending-selenium-ide/</guid>
		<description><![CDATA[how to extend and add your own commands to the selenium ide]]></description>
			<content:encoded><![CDATA[<p>In the previous <a href="http://www.codediesel.com/php/selenium-ide-tutorial-part-1/">Selenium posts</a> we saw how to use the selenium IDE for testing web pages. In this post we will see how to extend the Selenium IDE by adding our own custom commands. </p>
<p>Selenium IDE offers many useful commands (often called Selenese) for testing purposes. You use this sequence of commands to create various tests. But many times these commands are not sufficient and you need to add your own custom commands. For example a reader recently requested on how to input unique email ids for testing. Of course you can easily do this using the Selenium RC server and a language like PHP or Java. But we want to accomplish this in the IDE itself.<br />
<span id="more-2307"></span></p>
<h4>Types of Selenium commands</h4>
<p>Selenium commands come in three varieties : Actions, Accessors and Assertions. Each Selenium command being given in the format below:</p>
<table style="background-color: #FDF7E7; height: 20px; width: 230px; border: 1px solid #c0c0c0;">
<tr>
<td style="border-right: 1px solid #c0c0c0;">command</td>
<td style="border-right: 1px solid #c0c0c0;">target</td>
<td>value</td>
</tr>
</table>
<p><strong>Actions</strong> are commands which in general modify the state of the application; <em>click</em>, <em>typeKeys</em>, <em>deleteCookie</em> etc. are all actions. Many actions also come with a sibling with a &#8220;AndWait&#8221; suffix added; e.g. ‘typeKeysAndWait’. This tells Selenium to wait until the page loads after performing the particular action.</p>
<p><strong>Accessors</strong> examine the state of the application and store the results in variables, e.g. &#8220;storeLocation&#8221;. </p>
<p><strong>Assertions</strong> are like Accessors, but they verify that the state of the application conforms to what is expected</p>
<p>In this post we will see how to write Selenium Action command using a simple example.</p>
<h4>Writing your first custom Selenium Action Command</h4>
<p>In the following example we will add a new action, ‘typeRandomEmail’, which generates a random email address and types it in an input field.</p>
<p>Every Selenium Action command starts with a &#8216;do&#8217; prefix. The corresponding action comprising &#8216;AndWait&#8217; is automatically registered.  e.g when we create the &#8216;typeRandomEmail&#8217; action, the &#8216;typeRandomEmailAndWait’ command is automatically added to the command list. An action command takes up to two parameters, which will be passed the second and third column values in the test table. In our example we will be using only one parameter &#8211; the locator id where the random email will be typed.</p>
<p>The following shows the code for the <em>typeRandomEmail</em> action.</p>

<div class="wp_codebox"><table><tr id="p230725"><td class="code" id="p2307code25"><pre class="javascript" style="font-family:monospace;">&nbsp;
Selenium.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">doTypeRandomEmail</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">/**
    * Sets the value of an input field to a random email id, 
    * as though you typed it in.
    *
    * @param locator an &lt;a href=&quot;#locators&quot;&gt;element locator&lt;/a&gt;
    */</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// All locator-strategies are automatically handled by &quot;findElement&quot;</span>
    <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">page</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">findElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009966; font-style: italic;">/* The following block generates a random email string */</span>
    <span style="color: #003366; font-weight: bold;">var</span> allowedChars <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;abcdefghiklmnopqrstuvwxyz&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> stringLength <span style="color: #339933;">=</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> randomstring <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>stringLength<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> rnum <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> allowedChars.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        randomstring <span style="color: #339933;">+=</span> allowedChars.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>rnum<span style="color: #339933;">,</span>rnum<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Append a domain name</span>
    randomstring <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;@somedomain.com&quot;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Replace the element text with the new text</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">browserbot</span>.<span style="color: #660066;">replaceText</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> randomstring<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Importing your custom commands in Selenium</h4>
<p>Now that we have completed writing our own action command, it is time to import it to the Selenium IDE. Your custom commands are usually added to the file ‘user-extensions.js’. By default the ‘user-extensions.js’ file does not exist, so you need to first create a blank file into which you will add the above code. Once that is done you then need to tell Selenium to load the particular extension file from the ‘Options’ menu.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options1.gif" alt="selenium_options_page" title="selenium_options_page" width="428" height="376" class="size-full wp-image-2313" /></a></p>
<p>Once you have added the file to the options page you need to restart the Selenium IDE for the changes to take effect.</p>
<p><strong>Whenever you add some new code or make changes to the exiting one in the ‘user-extensions.js’, you need to restart the Selenium IDE for the changes to take effect.</strong></p>
<p>Now once you have restarted the IDE, you can see that your command has been added to the drop-down.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options_2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options_2.gif" alt="selenium_ide" title="selenium_ide" width="398" height="516" class="aligncenter size-full wp-image-2319" /></a></p>
<h4>Writing other Action commands</h4>
<p>You may be wondering how to go about writing other Selenium Action commands; what the <em>this.browserbot</em> object means and where it is defined. Although no clear documentation exists, the Selenium source code can itself be a valuable tool. All the Selenium commands are stored in the &#8216;selenium-api.js&#8217; file. I have included it <a href="http://www.codediesel.com/data/code/selenium-api.js">here</a> for easy download and reference. The original source file and other support files are located in the &#8216;selenium-ide.jar&#8217; file in your Selenium installation directory. Unzip that file and you have all the Selenium source code at your disposal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/testing/adding-custom-commands-to-the-selenium-ide/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Test dependencies in PHPUnit 3.4</title>
		<link>http://www.codediesel.com/testing/test-dependencies-in-phpunit/</link>
		<comments>http://www.codediesel.com/testing/test-dependencies-in-phpunit/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 08:54:33 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[phpunit]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/sql/test-dependencies-in-phpunit/</guid>
		<description><![CDATA[writing dependent tests in phpunit 3.4]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.phpunit.de/" rel="nofollow" target="_blank" >PHPUnit</a> has become the de-facto standard for unit testing PHP code. Now in version 3.4, it has added many new and interesting features to its repertoire.</p>
<h4>Dependencies in PHPUnit tests</h4>
<p>PHPUnit 3.4 now supports dependencies between different test methods. It allows you to execute a particular test <em>ONLY IF</em> the test that it depends on executes successfully. Take the following example (Listing 1.) where we test a <a href="http://www.codediesel.com/php/linked-list-in-php/">linked-list class</a> I developed earlier.<br />
<span id="more-2217"></span></p>
<h4>A simple unit-test with PHPUnit</h4>
<p>The test basically creates a link-list with 100 nodes, and tests a few class methods &#8211; reverseList, deleteFirstNode, deleteLastNode. As you can see the linklist creation part and method tests are combined in the single test method <em>testLinkList()</em>. </p>
<p>The primary focus here is on testing the three class functions. There is nothing wrong with this. But what if the linklist creation part itself fails before the other tests are conducted? Of course we can add another test to check that the links are being created correctly, but that mixes up the two parts.</p>
<p><b>Listing 1.</b></p>

<div class="wp_codebox"><table><tr id="p221726"><td class="code" id="p2217code26"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'linklist.class.php'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'PHPUnit/Framework.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> LinkListTest <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Framework_TestCase
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/* How many nodes to create */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_nNodes</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testLinkList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #009933; font-style: italic;">/* Linklist creation block */</span>
        <span style="color: #000088;">$theList</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>  
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertLast</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #009933; font-style: italic;">/* 
            Linklist methods testing block :
&nbsp;
            $theList-&gt;totalNodes() is a public function 
            in the 'linklist' class that returns the total
            number of nodes in the link-list.
        */</span>
&nbsp;
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reverseList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteFirstNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteLastNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Splitting up tests</h4>
<p>A better way is to split the linklist creation part and class method testing part into two separate test functions as below (Listing 2). Here the linklist is created in the &#8216;testCreateList()&#8217; method and the testing of the class methods is done in the &#8216;testLinkList()&#8217; method. This allows us to keep the two testing blocks separate.</p>
<p><b>Listing 2.</b></p>

<div class="wp_codebox"><table><tr id="p221727"><td class="code" id="p2217code27"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'linklist.class.php'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'PHPUnit/Framework.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> LinkListTest <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Framework_TestCase
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/* How many nodes to create */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_nNodes</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testCreateList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$theList</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertLast</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertTrue</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theList</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @depends testCreateList
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testLinkList<span style="color: #009900;">&#40;</span><span style="color: #000088;">$theList</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reverseList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteFirstNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteLastNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The important point to note here is that we have specified that the &#8216;<em>testLinkList</em>&#8216; method depends on the &#8216;<em>testCreateList</em>&#8216; method, with a @depends annotation. This tells PHPUnit that if the &#8216;<em>testCreateList</em>&#8216;  test fails then the test dependent on it, &#8216;<em>testLinkList</em>&#8216;, will have to be skipped, which is a logical way to go.</p>

<div class="wp_codebox"><table><tr id="p221728"><td class="code" id="p2217code28"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * @depends testCreateList
 */</span></pre></td></tr></table></div>

<h4>Producers &#038; Consumers in a Test</h4>
<p>First some definitions:</p>
<blockquote><p>
a. A producer is a test method that yields its unit under test as return value.<br />
b. A consumer is a test method that depends on one or more producers and their return values.
</p></blockquote>
<p>What it means is that a &#8216;Producer&#8217; is a test method that returns some data that will be used by a &#8216;Consumer&#8217; test method. In our example the &#8216;<em>testCreateList</em>&#8216; is a Producer and the &#8216;<em>testLinkList</em>&#8216; is the Consumer.  The &#8216;<em>testCreateList</em>&#8216; method returns a linklist object which is then received by the dependent method &#8216;<em>testLinkList</em>&#8216;. So if for some reason the &#8216;<em>testCreateList</em>&#8216; fails to return some data then the test that depends on it,  &#8216;<em>testLinkList</em>&#8216;, will have to be skipped, as it has nothing to work with.</p>
<p>Bear in mind that it does not mean that every test method that depends on some other method has to accept some arguments from the method it is dependent on. Lets breakup the above example further (Listing 3). Here we have added one more test method, &#8216;<em>testNodesDefined</em>&#8216;, which makes sure that the &#8216;$_nNodes&#8217; variable is not null. The &#8216;<em>testCreateList</em>&#8216; method is dependent on this method, so that if the &#8216;$_nNodes&#8217; is null then the &#8216;<em>testCreateList</em>&#8216; is skipped, which causes the test &#8216;<em>testLinkList</em>&#8216; to be skipped.</p>
<p><b>Listing 3.</b></p>

<div class="wp_codebox"><table><tr id="p221729"><td class="code" id="p2217code29"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'linklist.class.php'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'PHPUnit/Framework.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> LinkListTest <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Framework_TestCase
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/* How many nodes to create */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_nNodes</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testNodesDefined<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertNotNull</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @depends testNodesDefined
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testCreateList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$theList</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertLast</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertTrue</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theList</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @depends testCreateList
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testLinkList<span style="color: #009900;">&#40;</span><span style="color: #000088;">$theList</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reverseList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteFirstNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteLastNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theList</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">totalNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p> A output from a failed test, when we set  &#8216;$_nNodes&#8217; to null, is shown below.<br />
<b>Listing 4.</b></p>

<div class="wp_codebox"><table><tr id="p221730"><td class="code" id="p2217code30"><pre class="text" style="font-family:monospace;">D:\localhost\datastructures&gt;phpunit --verbose LinkListTest
PHPUnit 3.4.2 by Sebastian Bergmann.
&nbsp;
LinkListTest
FSS
&nbsp;
Time: 0 seconds
&nbsp;
There was 1 failure:
&nbsp;
1) LinkListTest::testNodesDefined
Failed asserting that &lt;null&gt; is not null.
&nbsp;
D:\localhost\test\datastructures\LinkListTest.php:13
&nbsp;
There were 2 skipped tests:
&nbsp;
1) LinkListTest::testCreateList
This test depends on &quot;LinkListTest::testNodesDefined&quot; to pass.
&nbsp;
&nbsp;
2) LinkListTest::testLinkList
This test depends on &quot;LinkListTest::testCreateList&quot; to pass.
&nbsp;
&nbsp;
FAILURES!
Tests: 1, Assertions: 2, Failures: 1, Skipped: 2.
&nbsp;
D:\localhost\test\datastructures&gt;</pre></td></tr></table></div>

<blockquote><p>
Note: The tests are executed in the sequence in which you wrote them. So take care while writing dependent tests. For example, sequencing test methods as below will not work.
</p></blockquote>

<div class="wp_codebox"><table><tr id="p221731"><td class="code" id="p2217code31"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testNodesDefined<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertNotNull</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_nNodes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @depends testCreateList
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testLinkList<span style="color: #009900;">&#40;</span><span style="color: #000088;">$theList</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #339933;">..</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @depends testNodesDefined
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testCreateList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #339933;">..</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>What all of this has brought us</h4>
<p>Testing a complex class in a single humongous test method is not wrong, but can create a confusing mess of &#8216;asserts&#8217;. Splitting a single test method into multiple dependent tests can help you segregate your test methods by functionality which in turn will get you to quickly localize defects in your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/testing/test-dependencies-in-phpunit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Running Selenium TestRunner slowly</title>
		<link>http://www.codediesel.com/testing/running-selenium-testrunner-slowly/</link>
		<comments>http://www.codediesel.com/testing/running-selenium-testrunner-slowly/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 04:43:39 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/sql/running-selenium-testrunner-slowly/</guid>
		<description><![CDATA[slow down the fast execution of selenium testrunner]]></description>
			<content:encoded><![CDATA[<p>By default Selenium TestRunner executes the test blindingly fast. You can however slow down the execution by using the speed controller slider in the right pane, which adds a maximum delay of 1 second after every command execution. But you have to do that manually for every test, and the maximum delay you get is 1 second. You can however increase the delay and also set the default delay rate by editing the <em>selenium-testrunner.js</em> file.<br />
<span id="more-2014"></span></p>
<h4>Editing the selenium-testrunner.js file</h4>
<p>First you have to find the &#8216;selenium-testrunner.js&#8217; file. It is located in your &#8216;Windows\Application Data&#8217; directory. The rough path is given below:</p>

<div class="wp_codebox"><table><tr id="p201432"><td class="code" id="p2014code32"><pre class="text" style="font-family:monospace;">Documents and Settings\Application Data\Mozilla\Firefox\
Profiles\extensions\{a6fd85ed-t567-s34f-a5af-ddf48bda539f}\content-files</pre></td></tr></table></div>

<p>Your exact directory path will be different. It is best do do a search for the file in your &#8216;Mozilla&#8217; directory. Once you have found it, you can look for the following lines of code:</p>

<div class="wp_codebox"><table><tr id="p201433"><td class="code" id="p2014code33"><pre class="javascript" style="font-family:monospace;">reset<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">runInterval</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speedController</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>._switchContinueButtonToPause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></td></tr></table></div>

<p>and replace it with:</p>

<div class="wp_codebox"><table><tr id="p201434"><td class="code" id="p2014code34"><pre class="javascript" style="font-family:monospace;">reset<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">runInterval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">2000</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>._switchContinueButtonToPause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></td></tr></table></div>

<p>This will by default add a 2 second delay after every command execution. Note that as we have made hardcoded changes to the speed variables, the speed slider in the TestRunner window will no longer have any effect on the execution.</p>
<h4>Setting the default speed controller delay to a high value</h4>
<p>In view of a recent comment, you can also set the default high delay for your slider by replacing the following lines in &#8216;selenium-testrunner.js&#8217;.</p>

<div class="wp_codebox"><table><tr id="p201435"><td class="code" id="p2014code35"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speedController</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Control.<span style="color: #660066;">Slider</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'speedHandle'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'speedTrack'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            range<span style="color: #339933;">:</span> $R<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onSlide<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onChange<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_codebox"><table><tr id="p201436"><td class="code" id="p2014code36"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speedController</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Control.<span style="color: #660066;">Slider</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'speedHandle'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'speedTrack'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            range<span style="color: #339933;">:</span> $R<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onSlide<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onChange<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Which will set the default delay to 100 milliseconds and the maximum to 5 seconds. Now you can also use the speed slider.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/testing/running-selenium-testrunner-slowly/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Where did that bug come from?</title>
		<link>http://www.codediesel.com/software/where-did-that-bug-come-from/</link>
		<comments>http://www.codediesel.com/software/where-did-that-bug-come-from/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 15:44:25 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1988</guid>
		<description><![CDATA[how small changes in code can introduce bugs]]></description>
			<content:encoded><![CDATA[<p>This is the second time this week that I encountered a annoying bug, introduced just by a small change in the code. Just when you think you can get away with minor changes without testing, you are in for a surprise.</p>
<p>The most common sense thing you can do is to test your code even for small changes; whether you are testing it yourself or sending it to the testing team. Seems simple, but how many times have you really done that. Its not that we are stupid, rather software was never so simple. Maybe we are careless sometimes. The moral is plain &#8211; treat even small changes important, and move it through a test before committing it to a version control.<br />
<span id="more-1988"></span><br />
The following figure from Steve Mcconnell&#8217;s <a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670" rel="nofollow" >Code Complete</a> shows the relation between lines of code changed and errors introduced.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/11/bug_source.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/bug_source.gif" alt="bug_source" title="bug_source" width="430" height="235" class="aligncenter size-full wp-image-1990" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/software/where-did-that-bug-come-from/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Test data generation for MySQL</title>
		<link>http://www.codediesel.com/data/test-data-generation-for-mysql/</link>
		<comments>http://www.codediesel.com/data/test-data-generation-for-mysql/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 09:28:16 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1833</guid>
		<description><![CDATA[generating test data for mysql]]></description>
			<content:encoded><![CDATA[<p>One of the most time consuming steps in developing a database based application is test data generation. Imagine you have created a shopping cart application for your client, containing dozens of tables and hundreds of fields. Everything is ready for testing, but the problem is your database is empty. You at least require a modicum of test data in the database to proceed with the testing. You can choose to manually enter a small set of random data into the database, but you lose a couple of precious days in the process. What you require is a data generator that automatically generates test data for your database.<br />
<span id="more-1833"></span><br />
There are a couple of data generators available for free on the web, but they are only suitable if your database schema is small, with no more than three to four tables and total number of fields not exceeding  a dozen or so.  While browsing I came across <a href="http://www.upscene.com/products.adg.index.php" rel="nofollow" target="_blank" >Advanced Data Generator (ADG)</a>, a test data generator for MySQL. ADG allows you to generate a random test data for dates, URLS, E-mail addresses, cities, names, countries and more. </p>
<h4>Data Generation</h4>
<p>Once you connect ADG to your MySQL server and register a database, you are ready to go. Generating the test data is quite simple. First you create a project for your data generation work. Once done, you select the table and fields you want to generate data for, select the type of test data to generate – dates, urls, names etc. Set the total number of records to generate and then run the project. This will create the test data for your database project. The test data can be saved directly to the connected database or you can save it as a separate SQL script, YAML or CSV file.  Below is a sample screenshot of a data generation project.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/11/adg1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/adg1-300x267.gif" alt="adg1" title="adg1" width="300" height="267" class="aligncenter size-medium wp-image-1832" /></a></p>
<p>The Advanced Data Generator comes with a very useful repository of real-life like data, in order to generate meaningful test-data for the database. You can also use custom SQL scripts or Macros to generate custom string data.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/11/adg2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/adg2-295x300.gif" alt="adg2" title="adg2" width="295" height="300" class="aligncenter size-medium wp-image-1838" /></a></p>
<h4>In closing</h4>
<p>Although not free, its a small price to pay for the excellent automation it provides during database creation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/test-data-generation-for-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

