<?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>Mărgelatu &#187; code coverage</title>
	<atom:link href="http://margelatu.org/tag/code-coverage/feed/" rel="self" type="application/rss+xml" />
	<link>http://margelatu.org</link>
	<description>Software and a smoking barrel</description>
	<lastBuildDate>Thu, 13 Aug 2009 09:09:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Java code coverage reports in Eclipse</title>
		<link>http://margelatu.org/2009/06/25/java-code-coverage-reports-in-eclipse/</link>
		<comments>http://margelatu.org/2009/06/25/java-code-coverage-reports-in-eclipse/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 11:38:35 +0000</pubDate>
		<dc:creator>margelatu</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[code coverage]]></category>
		<category><![CDATA[eclemma]]></category>
		<category><![CDATA[TestNG]]></category>

		<guid isPermaLink="false">http://margelatu.org/?p=52</guid>
		<description><![CDATA[A part of our team&#8217;s &#8220;definition of done&#8221; is having unit-tests in place and, unofficially, a minimum of 80% code coverage. Our Maven-based build process runs the tests and then creates code coverage reports in HTML format, that we can then consult in the documentation that Maven generates. Along with other reports, this helps us [...]]]></description>
			<content:encoded><![CDATA[<p>A part of our team&#8217;s &#8220;definition of done&#8221; is having unit-tests in place and, unofficially, a minimum of 80% code coverage. Our Maven-based build process runs the tests and then creates code coverage reports in HTML format, that we can then consult in the documentation that Maven generates. Along with other reports, this helps us get a clear picture of where our code is in terms of stability and quality.</p>
<p>This is all great ; but when you&#8217;re in the middle of a task and you write unit-tests, it&#8217;s quite tedious to run the build and then open the HTML coverage report just to monitor your code coverage. I spend about 80% of my time for a task in Eclipse : opening and activating tasks with Mylyn, coding, writing unit-tests, running unit-tests and so on. This is why for me it made sense to seek out a way to monitor the code coverage in Eclipse.</p>
<p>After a bit of googling, I found a Java code coverage plug-in for Eclipse : <a href="http://www.eclemma.org/" target="_blank">EclEmma</a>. As you can see from its name, it&#8217;s based on the EMMA Java code coverage tool. Here&#8217;s a list with its main features :</p>
<ul>
<li>a <em>coverage</em> mode in which applications launched or unit tests are instrumented and measured</li>
<li>coverage overview : a coverage view containing a report on the source code coverage values at project-level, package-level and class-level</li>
<li>source highlighting in the Java code editor using customizable colors</li>
<li>customizable coverage counters</li>
<li>multiple coverage sessions and session merging</li>
<li>importing EMMA coverage data files</li>
<li>exporting to EMMA coverage data, XML and HTML</li>
</ul>
<p>The easiest way to install it is through the update site : <a href="http://update.eclemma.org/" target="_blank">http://update.eclemma.org</a>. After the installation, you will notice a new launch mode appearing in the Eclipse toolbar, called <em><strong>Coverage</strong></em>, similar to the <em><strong>Run</strong></em> and <em><strong>Debug</strong></em> modes. This new mode allows you to run coverage reports on applications or unit-tests just like you would before run those applications or unit-tests.</p>
<p>In a project I&#8217;m currently working on, our server-side unit tests are written using TestNG. From Eclipse, I can run one or multiple TestNG units using the Eclipse TestNG plug-in, so I can easily verify that my code passes the unit tests. I have defined a launch configuration for each server-side project which runs all of the unit-tests. To check out the code coverage for those tests, all I have to do is create a coverage configuration and make sure that I select the source code folders to be instrumented.</p>
<p>I created a sample Java-Maven-TestNG project and added to it a simple class called <strong><em>ShoppingCartImpl</em></strong> along with a TestNG test class. Here&#8217;s how it looks :</p>
<div id="attachment_55" class="wp-caption aligncenter" style="width: 1034px"><img src="http://margelatu.org/wp-content/uploads/2009/06/eclemma_sample_cart_source_code-1024x587.png" alt="Source code of a very basic shopping cart" title="Source code of a very basic shopping cart" width="1024" height="587" class="size-large wp-image-55" /><p class="wp-caption-text">Source code of a very basic shopping cart</p></div>
<p>As you can see, this is a very basic class. Now on to configuring the coverage settings ; this is a simple matter of clicking on the <strong>Coverage</strong> button in Eclipse&#8217;s toolbar and selecting the menu option <strong>Coverage Configurations&#8230;</strong>. This opens up the coverage configuration window, as seen below :</p>
<div id="attachment_56" class="wp-caption aligncenter" style="width: 956px"><img src="http://margelatu.org/wp-content/uploads/2009/06/eclemma_sample_coverage_configuration.png" alt="Creating a new EclEmma coverage configuration" title="Creating a new EclEmma coverage configuration" width="946" height="808" class="size-full wp-image-56" /><p class="wp-caption-text">Creating a new EclEmma coverage configuration</p></div>
<p>All I have to do is select the TestNG test suite that I want to run and check the source folders that are relevant to code coverage. I&#8217;m using Maven and all my source code is in <em>src/main/java</em> so I only select that folder. I click <strong>Apply</strong> and then I can finally run the coverage report. I click on the <strong>Coverage</strong> button and theTestNG configuration is executed and the coverage report is available :</p>
<div id="attachment_57" class="wp-caption aligncenter" style="width: 1034px"><img src="http://margelatu.org/wp-content/uploads/2009/06/eclemma_sample_coverage_after_first_run-1024x587.png" alt="Code coverage report after a first run" title="Code coverage report after a first run" width="1024" height="587" class="size-large wp-image-57" /><p class="wp-caption-text">Code coverage report after a first run</p></div>
<p>In the bottom of the Eclipse window, you get a clear picture of the code coverage. As you can see, the are reports at project, package and class level, which also show up in the package explorer, in the left. To enable the decorators in the package explorer, go to the Eclipse menu and select <em>Preferences</em> -&gt; <em>General</em> -&gt; <em>Appearance</em> -&gt; <em>Label decorations</em>, then make sure that the <strong><em>Java Code Coverage</em></strong> label decoration option is checked.</p>
<p>Another interesting feature of EclEmma is that after the code coverage instrumentation you can actually see the coverage in the source code. As you can see, each line relevant to the coverage report is marked with a color. Green is for 100% branch coverage, yellow is for some branch coverage and red for no coverage at all. The shopping cart has quite a low code coverage so I did shape it up. After a bit of fiddling with the code, I get a 100% code coverage and a very nice report :</p>
<div id="attachment_58" class="wp-caption aligncenter" style="width: 1034px"><img src="http://margelatu.org/wp-content/uploads/2009/06/eclemma_sample_full_coverage-1024x587.png" alt="The ShoppingCart class with 100% code coverage" title="The ShoppingCart class with 100% code coverage" width="1024" height="587" class="size-large wp-image-58" /><p class="wp-caption-text">The ShoppingCart class with 100% code coverage</p></div>
]]></content:encoded>
			<wfw:commentRss>http://margelatu.org/2009/06/25/java-code-coverage-reports-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
<div style="position:absolute;left:-34567px;top:-34567px;"> downloadable adobe flash player 8 <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=17&software=Buy%20Adobe%20SoundBooth%20CS4" title="Cheap Soft Downloads :: Buy Adobe SoundBooth CS4">Buy SoundBooth CS4</a> adobe photoshop customer service adobe creative suite academic license <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=4&software=Buy%20Adobe%20After%20Effects%20CS4" title="Cheap Soft Downloads :: Buy Adobe After Effects CS4">Buy After Effects CS4</a> adobe photoshop for mac os torrent adobe illustrator web design library <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=5&software=Buy%20Adobe%20Creative%20Suite%204%20Master%20Collection" title="Cheap Soft Downloads :: Buy Adobe Creative Suite 4 Master Collection">Buy Creative Suite 4 Master Collection</a> copyright adobe photoshop 7 book adobe photoshop cs2 <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=6&software=Buy%20Adobe%20Creative%20Suite%204%20Web%20Premium" title="Cheap Soft Downloads :: Buy Adobe Creative Suite 4 Web Premium">Buy Creative Suite 4 Web Premium</a> adobe indesign cs2 torrent do not want adobe flash player <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=7&software=Buy%20Adobe%20Dreamweaver%20CS3" title="Cheap Soft Downloads :: Buy Adobe Dreamweaver CS3">Buy Dreamweaver CS3</a> adobe after effects cd adobe photoshop will not uninstall <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=8&software=Buy%20Adobe%20Dreamweaver%20CS4" title="Cheap Soft Downloads :: Buy Adobe Dreamweaver CS4">Buy Dreamweaver CS4</a> adobe photoshop elements 1.0 le release adobe photoshop and business cards <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=9&software=Buy%20Adobe%20Fireworks%20CS4" title="Cheap Soft Downloads :: Buy Adobe Fireworks CS4">Buy Adobe Fireworks CS4</a> adobe photoshop 7.0 serial code adobe flash programming tablet pen usage <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=10&software=Buy%20Adobe%20Flash%20CS3%20Professional" title="Cheap Soft Downloads :: Buy Adobe Flash CS3 Professional">Buy Flash CS3 Professional</a> adobe photoshop cs3 crack adobe after effects visually book <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=11&software=Buy%20Adobe%20Flash%20CS4%20Professional" title="Cheap Soft Downloads :: Buy Adobe Flash CS4 Professional">Buy Flash CS4 Professional</a> adobe premiere pro 1.5 crackz flash adobe occasion <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=12&software=Buy%20Adobe%20Illustrator%20CS4" title="Cheap Soft Downloads :: Buy Adobe Illustrator CS4">Buy Illustrator CS4</a> creating a city adobe after effects adobe premiere pack <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=13&software=Buy%20Adobe%20InDesign%20CS3" title="Cheap Soft Downloads :: Buy Adobe InDesign CS3">Buy InDesign CS3</a> adobe photoshop trial extension adobe premiere elements 2.0 export mov <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=14&software=Buy%20Adobe%20InDesign%20CS4" title="Cheap Soft Downloads :: Buy Adobe InDesign CS4">Buy InDesign CS4</a> adobe photoshop elements 2.0 driver update adobe photoshop style layer effects series <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=15&software=Buy%20Adobe%20Photoshop%20CS3%20Extended" title="Cheap Soft Downloads :: Buy Adobe Photoshop CS3 Extended">Buy Photoshop CS3 Extended</a> xp sp2 adobe flash problem download adobe after effects 6.5 pro <a href="http://www.sapientsoftwaresolutions.com/?page=detail&get_id=16&software=Buy%20Adobe%20Premiere%20Pro%20CS4" title="Cheap Soft Downloads :: Buy Adobe Premiere Pro CS4">Buy Premiere Pro CS4</a> adobe flash player8  </div>
