<?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>Modular Mind &#187; Testing</title>
	<atom:link href="http://www.modumind.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.modumind.com</link>
	<description>Eclipse RCP and OSGi training - online or onsite</description>
	<lastBuildDate>Thu, 18 Feb 2010 19:07:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Updated PDE Build and Test Example</title>
		<link>http://www.modumind.com/2008/08/04/updated-pde-build-and-test-example/</link>
		<comments>http://www.modumind.com/2008/08/04/updated-pde-build-and-test-example/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 22:31:04 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Builds]]></category>
		<category><![CDATA[Rich Client Platform]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=100</guid>
		<description><![CDATA[I&#8217;ve just spent some time updating my example showing how to set up PDE Build and the Eclipse Testing Framework. I&#8217;ve generally cleaned things up and I&#8217;m now creating the test environment in the correct way.
As a special bonus, I&#8217;ve also thrown in coverage analysis using EMMA. And before people ask, yes I have tried [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just spent some time updating my example showing how to set up PDE Build and the <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.test/testframework.html?view=co">Eclipse Testing Framework</a>. I&#8217;ve generally cleaned things up and I&#8217;m now <a href="http://rcpquickstart.com/2008/08/01/creating-a-test-environment-for-the-eclipse-testing-framework/">creating the test environment in the correct way</a>.</p>
<p>As a special bonus, I&#8217;ve also thrown in coverage analysis using <a href="http://emma.sourceforge.net/">EMMA</a>. And before people ask, yes I have tried to use <a href="http://www.atlassian.com/software/clover/">Clover</a> with PDE Build, but have had little luck due to Clover&#8217;s dependence on a specialized Java complier. If anyone has gotten this to work, I&#8217;d love to hear about it.</p>
<p>And finally, I had to change this example to use a test plug-in instead of a test fragment. For some reason when running Eclipse 3.4 (maybe related to p2?), the ETF is not finding tests in fragments. If anyone has any ideas here as well, please let me know.</p>
<p>You can download the new example <a href="http://idisk.mac.com/pjpaulin-public/rcpquickstart/pdebuild-and-test-example.zip">here</a>.</p>
<p><em>NOTE: I&#8217;ve discovered that the EMMA instrumentation task fails if you&#8217;re running the script inside of Eclipse and you have spaces in your workspace path. Avoid spaces in your path and you should be good to go.</em></p>
<p><em>Update &#8211; October 6, 2009: The sample projects have now been updated to work with Eclipse 3.5.1</em></p>
<a href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="DZone" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a> <a href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Digg" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Evernote" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a> <a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a> <a href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/squidoo?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Squidoo" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/squidoo.png" width="16" height="16" alt="Squidoo"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a> <a href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a> <a href="http://www.addtoany.com/add_to/yahoo_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example" title="Yahoo Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/yahoo.png" width="16" height="16" alt="Yahoo Bookmarks"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F08%2F04%2Fupdated-pde-build-and-test-example%2F&amp;linkname=Updated%20PDE%20Build%20and%20Test%20Example">Share/Save</a>]]></content:encoded>
			<wfw:commentRss>http://www.modumind.com/2008/08/04/updated-pde-build-and-test-example/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>Running Unit Tests for RCP and OSGi Applications</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/</link>
		<comments>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 22:11:49 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Builds]]></category>
		<category><![CDATA[Rich Client Platform]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71</guid>
		<description><![CDATA[Eclipse provides great tools for testing RCP and OSGi applications using JUnit, but there a few areas that are problematic.

It&#8217;s not easy to run all the tests in a set of plug-ins. The test launcher allows you to run all the tests in a single project, but RCP and OSGi developers are usually working with [...]]]></description>
			<content:encoded><![CDATA[<p>Eclipse provides great tools for testing RCP and OSGi applications using JUnit, but there a few areas that are problematic.</p>
<ul>
<li>It&#8217;s not easy to run all the tests in a set of plug-ins. The test launcher allows you to run all the tests in a single project, but RCP and OSGi developers are usually working with a large set of test plug-ins. Sure it&#8217;s possible to create test suites, but keeping suites up-to-date is a real pain.</li>
<li>It&#8217;s not easy to use test fragments. To find out why you&#8217;d want to use test fragments instead of test plug-ins, check out my previous post on <a href="http://rcpquickstart.wordpress.com/2007/06/20/unit-testing-plug-ins-with-fragments/">Testing Plug-ins with Fragments</a>. The problem is that even the standard suite-based solution does not work with fragments. There are workarounds, but they&#8217;re not very pretty.</li>
<li>It&#8217;s not easy to run all of your tests during an automated build using the <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.test/testframework.html?view=co">Eclipse Testing Framework</a>. This is related to the first point above, and again you can use suites to handle this. </li>
</ul>
<div>So to sum things up, I want to run sets of tests across multiple plug-ins or fragments and I don&#8217;t want to use suites. My solutions has been to create a simple bundle test collection plug-in that harvests unit tests based on a set of filters. To use the plug-in, you need to do the following:</div>
<div>
<ol>
<li><a href="http://idisk.mac.com/pjpaulin-public/rcpquickstart/bundletestcollector.zip">Download</a> the bundle test collector which is licensed under the standard <a href="http://www.eclipse.org/org/documents/epl-v10.html">EPL</a>. The archive contains the test collector plug-in and also an example plug-in showing proper usage.</li>
<li>Add the <code>com.rcpquickstart.bundletestcollector</code> plug-in to your workspace.</li>
<li>Create a plug-in that will contain a suite or set of suites that will load tests based on filters. The tests making up the suites will be generated dynamically, so you won&#8217;t need to maintain them. This plug-in will need to depend on the <code>com.rcpquickstart.bundletestcollector</code> and junit plug-ins, but that&#8217;s it.</li>
<li>In your suite, add the following method:
<pre class="brush: css">	public static Test suite() {
		BundleTestCollector testCollector = new BundleTestCollector();

		TestSuite suite = new TestSuite(&quot;All Tests&quot;);

		/*
		 * assemble as many collections as you like based on bundle, package and
		 * classname filters
		 */
		testCollector.collectTests(suite, &quot;com.mycompany.&quot;, &quot;com.mycompany.mypackage.&quot;,
				&quot;*Test&quot;);

		return suite;

	}</pre>
</li>
</ol>
</div>
<p> </p>
<p>You can then run the test suite both inside of the Eclipse IDE and using the Eclipse Testing Framework. I should note that this works only for JUnit 3.x tests. JUnit 4 describes suites using annotations which makes it (as far as I can tell) impossible to dynamically generate a suite at runtime. If anyone has a solution to this, I&#8217;d love to hear it. </p>
<p>As always, comments and fixes are much appreciated.</p>
<a href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="DZone" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a> <a href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Digg" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Evernote" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a> <a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a> <a href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/squidoo?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Squidoo" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/squidoo.png" width="16" height="16" alt="Squidoo"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a> <a href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a> <a href="http://www.addtoany.com/add_to/yahoo_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications" title="Yahoo Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/yahoo.png" width="16" height="16" alt="Yahoo Bookmarks"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.modumind.com%2F2008%2F06%2F12%2Frunning-unit-tests-for-rcp-and-osgi-applications%2F&amp;linkname=Running%20Unit%20Tests%20for%20RCP%20and%20OSGi%20Applications">Share/Save</a>]]></content:encoded>
			<wfw:commentRss>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Running Automated Tests with PDE Build</title>
		<link>http://www.modumind.com/2007/08/06/running-automated-tests-with-pde-build/</link>
		<comments>http://www.modumind.com/2007/08/06/running-automated-tests-with-pde-build/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 20:25:02 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Builds]]></category>
		<category><![CDATA[Rich Client Platform]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/2007/08/06/running-automated-tests-with-pde-build/</guid>
		<description><![CDATA[In a previous post, I provided a set of projects that you could use to get a sample build running quickly. The idea was that getting your first build running is half the battle. From that point on, you can make small, incremental changes to accomplish what you like.
A common request I&#8217;ve received, though, is [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://rcpquickstart.wordpress.com/2007/06/06/getting-started-with-pde-build/">previous post</a>, I provided a set of projects that you could use to get a sample build running quickly. The idea was that getting your first build running is half the battle. From that point on, you can make small, incremental changes to accomplish what you like.</p>
<p>A common request I&#8217;ve received, though, is to provide a similar sample build that includes the running of JUnits using the <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.test/testframework.html?view=co">Eclipse Test Framework</a>. Well  here it is! Just <a href="http://idisk.mac.com/pjpaulin-public/rcpquickstart/pdebuild-and-test-example.zip">download</a> and import the sample projects, and follow the directions in the included <code>readme.txt</code> file.</p>
<p><em>Note: If you want to run this sample build using Eclipse 3.2, you&#8217;ll need to work around a PDE Build <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=152577">defect</a>. For instructions on how to do this, check out the &#8220;Problems parsing feature file in a product build&#8221; section on the <a href="http://wiki.eclipse.org/index.php/PDEBuild">PDE Build wiki page</a>.</em></p>
<a href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="DZone" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a> <a href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Digg" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Evernote" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a> <a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a> <a href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/squidoo?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Squidoo" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/squidoo.png" width="16" height="16" alt="Squidoo"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a> <a href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a> <a href="http://www.addtoany.com/add_to/yahoo_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build" title="Yahoo Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/yahoo.png" width="16" height="16" alt="Yahoo Bookmarks"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F08%2F06%2Frunning-automated-tests-with-pde-build%2F&amp;linkname=Running%20Automated%20Tests%20with%20PDE%20Build">Share/Save</a>]]></content:encoded>
			<wfw:commentRss>http://www.modumind.com/2007/08/06/running-automated-tests-with-pde-build/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
		<item>
		<title>Testing Plug-ins with Fragments</title>
		<link>http://www.modumind.com/2007/06/20/unit-testing-plug-ins-with-fragments/</link>
		<comments>http://www.modumind.com/2007/06/20/unit-testing-plug-ins-with-fragments/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 19:07:48 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Rich Client Platform]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/2007/06/20/unit-testing-plug-ins-with-fragments/</guid>
		<description><![CDATA[As Eclipse plug-in and  Rich Client Platform developers, we face unique challenges  in how we structure and execute our unit tests. In this article, I suggest an approach to unit testing based on Eclipse fragments that can help us overcome these challenges. If you find yourself frustrated with your current plug-in testing options, [...]]]></description>
			<content:encoded><![CDATA[<p>As Eclipse plug-in and  Rich Client Platform developers, we face unique challenges  in how we structure and execute our unit tests. In this article, I suggest an approach to unit testing based on Eclipse fragments that can help us overcome these challenges. If you find yourself frustrated with your current plug-in testing options, read on!</p>
<p><span id="more-33"></span></p>
<p>But before going into detail on a fragment based solution, let&#8217;s examine the current approaches and the pros and cons associated with each. The first approach is the one most of us start with as we learn the ropes of plug-in development: placing all code in a single plug-in.</p>
<h3>Option 1: Place all code in a single plug-in</h3>
<p>Placing all your code in a single plug-in is obviously the simplest approach. Usually, developers who go down this path choose to place their code in two different source directories: <code>src</code> and <code>test</code>.</p>
<p><img src="http://rcpquickstart.files.wordpress.com/2007/06/unit-tests.png" alt="Placing all code in a single plug-in" /></p>
<p>In addition to being simple, this approach has the benefit of allowing all of your code to be loaded by the same classloader (each plug-in has its own classloader). This means that if you maintain the same package structure in your source and test folders, your test classes will have access to the non-public methods of the classes under test.</p>
<p>The downside to this approach is that it seriously complicates your build process. If you wish to run your tests as part of your build process (and who doesn&#8217;t), then you&#8217;ll need to include your test code in your deployable plug-ins. Your plug-ins will also need to declare dependencies on JUnit and any other test libraries you use (EasyMock, etc.). It&#8217;s possible to manually remove the classes and manifest entries after the build, but this is far from ideal.</p>
<h3>Option 2: Place test code in a separate plug-in</h3>
<p>To get around these build-related issues, many of us choose to place unit test code in a separate plug-in. Usually, each testable plug-in will have a corresponding test plug-in. This is the approach taken by most Eclipse projects, and it has the advantage of cleanly separating out test code and dependencies during the build process.</p>
<p><img src="/wp-content/uploads/2007/06/unit-tests-2.png" alt="Placing test code in a separate plug-in" /></p>
<p>The disadvantage of this approach, however, is that your test classes will be loaded by a separate classloader and will therefore not have access to the non-public methods of the classes under test. In addition, your tests will not have access to classes in packages not <em>exported</em> by the plug-in under test.</p>
<p>Plug-ins that are properly designed will typically export only a small set of API packages, keeping most of the implementation packages hidden from the outside world. But it&#8217;s often useful to have access to these implementation packages during testing. A common workaround  is to expose these packages as <em>friends</em> of the test plug-in. While this approach works, it pollutes your plug-in manifest with reference to test plug-ins. It also does nothing to solve the other issue of accessing non-public methods.</p>
<h3>Option 3: Place test code in a fragment</h3>
<p>Wouldn&#8217;t it be great if we could combine the classloading benefits of having a single plug-in with the clean separation of test code achieved with a separate plug-in? Well luckily for us, this is possible using Eclipse <em>fragments</em>.</p>
<p>A fragments looks much like a plug-in from the outside. It is represented as a separate project in your workspace, it contains a manifest that describes its contents, it is built and deployed as a jar. What makes a fragment different is that it contributes it&#8217;s resources at runtime to a single <em>host plug-in</em>. The classes in the fragment are therefore loaded by the host plug-in&#8217;s classloader.</p>
<p><img src="/wp-content/uploads/2007/06/unit-tests-3.png" alt="Placing test code in a fragment" /></p>
<p>By placing our unit tests in fragments, we can provide our tests access to the non-public methods of the classes under test. Also, because the source code and test code are actually part of the same plug-in, there are no issues related to non-exported packages. Test classes will have access to all packages in the plug-in, whether they are exported or not.</p>
<h3>Workaround: Creating a master test suite</h3>
<p>The main disadvantage to this fragment based approach is that it is difficult to aggregate unit tests into a master test suite. While it&#8217;s easy to create a test suite that includes the tests <em>within</em> a fragment, it&#8217;s not so easy to create a suite that includes the tests in <em>multiple</em> fragments.</p>
<p>The basic problem is that classes in fragments are not visible outside of the fragment itself. Any attempt to reference fragment classes in another plug-in will result in a compile error, so it&#8217;s not possible to assemble a master test suite in the standard way. But because the fragment classes are accessible via the host plug-in&#8217;s classloader at runtime, it is possible to create a master test suite using reflection. The code below shows how this can be done.</p>
<pre>public class AllTests {

	public static Test suite() throws ClassNotFoundException {
		TestSuite suite = new TestSuite(
				"Master test suite.");

		suite.addTest(getTest("com.mycompany.myplugin1.AllTests"));
		suite.addTest(getTest("com.mycompany.myplugin2.AllTests"));
		return suite;
	}

	private static Test getTest(String suiteClassName) {
		try {
			Class clazz = Class.forName(suiteClassName);
			Method suiteMethod = clazz.getMethod("suite", new Class[0]);
			return (Test) suiteMethod.invoke(null, new Object[0]);
		} catch (Exception e) {
			throw new RuntimeException("Error", e);
		}
	}
}</pre>
<p>Simply place this suite in a plug-in that declares dependencies on all testable plug-ins. You should then be able to run all of your tests with one click. While this code does add some complexity to the test suite, it is only necessary for the single master test suite class. The individual test suites in the fragments can be written normally.</p>
<p>UPDATE: For an alternative approach to running tests in fragments, see my post on <a href="/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/">Running Unit Tests for RCP and OSGi Applications</a>.</p>
<p>UPDATE 01/12/2009: Another alternative is to add a <code>Eclipse-ExtensibleAPI: true</code> entry to the manifest of the plug-in being tested. This header makes your fragment classes available to other plug-ins during development, and eliminates the need for the reflection workaround above. Thanks to Martin Dilger for the suggestion.</p>
<h3>Final thoughts</h3>
<p>There are some other minor issues with a fragment based approach. One of the most annoying is that the JUnit view in Eclipse does not allow you to double-click on a test case to open the class. For some reason, though, clicking on a line in the Failure Trace section does work. Go figure.</p>
<p>Overall, however, I&#8217;ve found that the benefits of fragment based unit testing far outweigh the disadvantages. If you are satisfied with the more traditional approaches to unit testing plug-ins, then by all means keep doing what you&#8217;re doing. But if you find yourself frustrated with the limitations of these approaches, give fragments a try. You&#8217;ll be glad you did!</p>
<a href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="DZone" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a> <a href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Digg" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Evernote" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a> <a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a> <a href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/squidoo?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Squidoo" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/squidoo.png" width="16" height="16" alt="Squidoo"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a> <a href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a> <a href="http://www.addtoany.com/add_to/yahoo_bookmarks?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments" title="Yahoo Bookmarks" rel="nofollow" target="_blank"><img src="http://www.modumind.com/wp-content/plugins/add-to-any/icons/yahoo.png" width="16" height="16" alt="Yahoo Bookmarks"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.modumind.com%2F2007%2F06%2F20%2Funit-testing-plug-ins-with-fragments%2F&amp;linkname=Testing%20Plug-ins%20with%20Fragments">Share/Save</a>]]></content:encoded>
			<wfw:commentRss>http://www.modumind.com/2007/06/20/unit-testing-plug-ins-with-fragments/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
	</channel>
</rss>
