<?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>maxheapsize.com &#187; unit</title>
	<atom:link href="http://maxheapsize.com/tag/unit/feed/" rel="self" type="application/rss+xml" />
	<link>http://maxheapsize.com</link>
	<description>Oliver Wehrens on Programming and Agile</description>
	<lastBuildDate>Tue, 14 Jun 2011 20:41:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Using TestNG with DataProviders to cover more test cases</title>
		<link>http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/</link>
		<comments>http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 22:51:44 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[testng]]></category>
		<category><![CDATA[unit]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=150</guid>
		<description><![CDATA[A couple of days ago I had the case that I needed to test a method with different parameters. I ended up writing a couple of test methods differing only in passing various arguments to the unit under test. Tonight I was at a TestNG talk and while I knew most of the stuff already [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F03%2F23%2Fusing-testng-with-dataproviders-to-cover-more-test-cases%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F03%2F23%2Fusing-testng-with-dataproviders-to-cover-more-test-cases%2F&amp;source=owehrens&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>A couple of days ago I had the case that I needed to test a method with different parameters. I ended up writing a couple of test methods <strong>differing only in passing various arguments</strong> to the unit under test. </p>
<p>Tonight I was at a <a href="http://newthinking-store.de/stammtisch/javausergroup/20090310">TestNG</a> talk and while I knew most of the stuff already the DataProviders (which I heard of before but unfortunately never really payed attention to) really caught me.</p>
<p>Now I can create a<strong> DataProvider which generates test data</strong>. Each of these data sets will result in call of the test method with the corresponding arguments. </p>
<p>The following code will test a String to Property Converter if it works correctly. It takes two parameters, first the string to be converted, second the result which I will assert.</p>
<pre class="brush: java; title: ;">
@Test(dataProvider = &quot;convertTestDataProvider&quot;)
public void testConvert(String property, String result)
{
    Properties properties =
      stringPropertyConverter.convertString(property);
    Assert.assertTrue(properties.get(&quot;A&quot;).equals(result));
  }
</pre>
<p>Now the DataProvider must return an array of array of objects. TestNG will cast the return values to the method signature of all the tests with the corresponding annotation.</p>
<pre class="brush: java; title: ;">
    @DataProvider(name = &quot;convertTestDataProvider&quot;)
    public Object[][] convertTestDataProvider()
    {
        return new Object[][]{
                {&quot;A=&quot;, &quot;&quot;},
                {&quot;A=1&quot;, &quot;1&quot;},
                {&quot;A=2=3&quot;, &quot;2=3&quot;},
                {&quot;A=2&quot; + StringPropertyConverter.ideaLineSeperator +
                 &quot;# Comment&quot; +
                 StringPropertyConverter.ideaLineSeperator + &quot;C=1&quot;, &quot;2&quot;},
        };
    }
</pre>
<p>Here I cover 4 test cases. It is very easy to add more tests just by adding one more line with the values to test and the expected result.</p>
<div class="wp-caption alignnone" style="width: 473px"><img alt="TestNG results with DataProvider" src="http://maxheapsize.com/static/TestNGWithDataProvider.jpg" title="TestNG results with DataProvider" width="463" height="312" /><p class="wp-caption-text">TestNG results with DataProvider</p></div>
<p>This will save me some amount of time.</p>
<p>Good Job <a href="http://beust.com/weblog/">Cedrik</a> &#038; friends.</p>
<p>Next step: How to make sure you cover all the relevant test cases (and having a systematic way of getting there). Anybody has an Idea?</p>
<div class="google_plusone_widget"><g:plusone 
      count="true" href="http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/" size="medium"></g:plusone></div><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;title=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;title=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Using+TestNG+with+DataProviders+to+cover+more+test+cases&amp;url=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;title=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;title=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;bm_description=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;title=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;title=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/&amp;title=Using+TestNG+with+DataProviders+to+cover+more+test+cases" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Using+TestNG+with+DataProviders+to+cover+more+test+cases+@+http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2009/03/23/using-testng-with-dataproviders-to-cover-more-test-cases/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

