<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Running Unit Tests for RCP and OSGi Applications</title>
	<atom:link href="http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/</link>
	<description>Eclipse RCP and OSGi training - online or onsite</description>
	<lastBuildDate>Tue, 31 Aug 2010 01:28:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: celeraman+</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-8776</link>
		<dc:creator>celeraman+</dc:creator>
		<pubDate>Sun, 23 May 2010 20:50:13 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-8776</guid>
		<description>This will make the job within a fragment based tests.
Put Eclipse-ExtensibleAPI: true into host plugin manifest file.

-- cut here --
package my.package

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Modifier;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.apache.log4j.Logger;
import org.junit.runners.model.InitializationError;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.Suite;

/**
 * Discovers all JUnit tests and runs them in a suite.
 */
@RunWith(AllTests.AllTestsRunner.class)
public final class AllTests {

  private static final File CLASSES_DIR = findClassesDir();

  private AllTests() {
    // static only
  }

  /**
   * Finds and runs tests.
   */
  public static class AllTestsRunner extends Suite {

    private final Logger _log = Logger.getLogger(getClass());

    /**
     * Constructor.
     *
     * @param clazz  the suite class - &lt;code&gt;AllTests&lt;/code&gt;
     * @throws InitializationError  if there&#039;s a problem
     * @throws org.junit.runners.model.InitializationError 
     */
	public AllTestsRunner(final Class clazz) throws InitializationError {
      super(clazz, findClasses());
    }

    /**
     * {@inheritDoc}
     * @see org.junit.runners.Suite#run(org.junit.runner.notification.RunNotifier)
     */
    @Override
    public void run(final RunNotifier notifier) {
      initializeBeforeTests();

      notifier.addListener(new RunListener() {
        @Override
        public void testStarted(final Description description) {
          if (_log.isTraceEnabled()) {
            _log.trace(&quot;Before test &quot; + description.getDisplayName());
          }
        }

        @Override
        public void testFinished(final Description description) {
          if (_log.isTraceEnabled()) {
            _log.trace(&quot;After test &quot; + description.getDisplayName());
          }
        }
      });

      super.run(notifier);
    }

    private static Class[] findClasses() {
      List classFiles = new ArrayList();
      findClasses(classFiles, CLASSES_DIR);
      List&lt;Class&gt; classes = convertToClasses(classFiles, CLASSES_DIR);
      return classes.toArray(new Class[classes.size()]);
    }

    private static void initializeBeforeTests() {
      // do one-time initialization here
    }

    private static List&lt;Class&gt; convertToClasses(
        final List classFiles, final File classesDir) {

      List&lt;Class&gt; classes = new ArrayList&lt;Class&gt;();
      for (File file : classFiles) {
        if (!file.getName().endsWith(&quot;Test.class&quot;)) {
          continue;
        }
        String name = file.getPath().substring(classesDir.getPath().length() + 1)
          .replace(&#039;/&#039;, &#039;.&#039;)
          .replace(&#039;\\&#039;, &#039;.&#039;);
        name = name.substring(0, name.length() - 6);
        Class c;
        try {
          c = Class.forName(name);
        }
        catch (ClassNotFoundException e) {
          throw new AssertionError(e);
        }
        if (!Modifier.isAbstract(c.getModifiers())) {
          classes.add(c);
        }
      }

      // sort so we have the same order as Ant
      Collections.sort(classes, new Comparator&lt;Class&gt;() {
        public int compare(final Class c1, final Class c2) {
          return c1.getName().compareTo(c2.getName());
        }
      });

      return classes;
    }

    private static void findClasses(final List classFiles, final File dir) {
      for (File file : dir.listFiles()) {
        if (file.isDirectory()) {
          findClasses(classFiles, file);
        }
        else if (file.getName().toLowerCase().endsWith(&quot;.class&quot;)) {
          classFiles.add(file);
        }
      }
    }
  }

  private static File findClassesDir() {
    try {
      String path = AllTests.class.getProtectionDomain()
        .getCodeSource().getLocation().getFile();
      return new File(URLDecoder.decode(path, &quot;UTF-8&quot;));
    }
    catch (UnsupportedEncodingException impossible) {
      // using default encoding, has to exist
      throw new AssertionError(impossible);
    }
  }
}

-- cut here --</description>
		<content:encoded><![CDATA[<p>This will make the job within a fragment based tests.<br />
Put Eclipse-ExtensibleAPI: true into host plugin manifest file.</p>
<p>&#8211; cut here &#8211;<br />
package my.package</p>
<p>import java.io.File;<br />
import java.io.UnsupportedEncodingException;<br />
import java.lang.reflect.Modifier;<br />
import java.net.URLDecoder;<br />
import java.util.ArrayList;<br />
import java.util.Collections;<br />
import java.util.Comparator;<br />
import java.util.List;</p>
<p>import org.apache.log4j.Logger;<br />
import org.junit.runners.model.InitializationError;<br />
import org.junit.runner.Description;<br />
import org.junit.runner.RunWith;<br />
import org.junit.runner.notification.RunListener;<br />
import org.junit.runner.notification.RunNotifier;<br />
import org.junit.runners.Suite;</p>
<p>/**<br />
 * Discovers all JUnit tests and runs them in a suite.<br />
 */<br />
@RunWith(AllTests.AllTestsRunner.class)<br />
public final class AllTests {</p>
<p>  private static final File CLASSES_DIR = findClassesDir();</p>
<p>  private AllTests() {<br />
    // static only<br />
  }</p>
<p>  /**<br />
   * Finds and runs tests.<br />
   */<br />
  public static class AllTestsRunner extends Suite {</p>
<p>    private final Logger _log = Logger.getLogger(getClass());</p>
<p>    /**<br />
     * Constructor.<br />
     *<br />
     * @param clazz  the suite class &#8211; <code>AllTests</code><br />
     * @throws InitializationError  if there&#8217;s a problem<br />
     * @throws org.junit.runners.model.InitializationError<br />
     */<br />
	public AllTestsRunner(final Class clazz) throws InitializationError {<br />
      super(clazz, findClasses());<br />
    }</p>
<p>    /**<br />
     * {@inheritDoc}<br />
     * @see org.junit.runners.Suite#run(org.junit.runner.notification.RunNotifier)<br />
     */<br />
    @Override<br />
    public void run(final RunNotifier notifier) {<br />
      initializeBeforeTests();</p>
<p>      notifier.addListener(new RunListener() {<br />
        @Override<br />
        public void testStarted(final Description description) {<br />
          if (_log.isTraceEnabled()) {<br />
            _log.trace(&#8220;Before test &#8221; + description.getDisplayName());<br />
          }<br />
        }</p>
<p>        @Override<br />
        public void testFinished(final Description description) {<br />
          if (_log.isTraceEnabled()) {<br />
            _log.trace(&#8220;After test &#8221; + description.getDisplayName());<br />
          }<br />
        }<br />
      });</p>
<p>      super.run(notifier);<br />
    }</p>
<p>    private static Class[] findClasses() {<br />
      List classFiles = new ArrayList();<br />
      findClasses(classFiles, CLASSES_DIR);<br />
      List&lt;Class&gt; classes = convertToClasses(classFiles, CLASSES_DIR);<br />
      return classes.toArray(new Class[classes.size()]);<br />
    }</p>
<p>    private static void initializeBeforeTests() {<br />
      // do one-time initialization here<br />
    }</p>
<p>    private static List&lt;Class&gt; convertToClasses(<br />
        final List classFiles, final File classesDir) {</p>
<p>      List&lt;Class&gt; classes = new ArrayList&lt;Class&gt;();<br />
      for (File file : classFiles) {<br />
        if (!file.getName().endsWith(&#8220;Test.class&#8221;)) {<br />
          continue;<br />
        }<br />
        String name = file.getPath().substring(classesDir.getPath().length() + 1)<br />
          .replace(&#8216;/&#8217;, &#8216;.&#8217;)<br />
          .replace(&#8216;\\&#8217;, &#8216;.&#8217;);<br />
        name = name.substring(0, name.length() &#8211; 6);<br />
        Class c;<br />
        try {<br />
          c = Class.forName(name);<br />
        }<br />
        catch (ClassNotFoundException e) {<br />
          throw new AssertionError(e);<br />
        }<br />
        if (!Modifier.isAbstract(c.getModifiers())) {<br />
          classes.add(c);<br />
        }<br />
      }</p>
<p>      // sort so we have the same order as Ant<br />
      Collections.sort(classes, new Comparator&lt;Class&gt;() {<br />
        public int compare(final Class c1, final Class c2) {<br />
          return c1.getName().compareTo(c2.getName());<br />
        }<br />
      });</p>
<p>      return classes;<br />
    }</p>
<p>    private static void findClasses(final List classFiles, final File dir) {<br />
      for (File file : dir.listFiles()) {<br />
        if (file.isDirectory()) {<br />
          findClasses(classFiles, file);<br />
        }<br />
        else if (file.getName().toLowerCase().endsWith(&#8220;.class&#8221;)) {<br />
          classFiles.add(file);<br />
        }<br />
      }<br />
    }<br />
  }</p>
<p>  private static File findClassesDir() {<br />
    try {<br />
      String path = AllTests.class.getProtectionDomain()<br />
        .getCodeSource().getLocation().getFile();<br />
      return new File(URLDecoder.decode(path, &#8220;UTF-8&#8243;));<br />
    }<br />
    catch (UnsupportedEncodingException impossible) {<br />
      // using default encoding, has to exist<br />
      throw new AssertionError(impossible);<br />
    }<br />
  }<br />
}</p>
<p>&#8211; cut here &#8211;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-2658</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Fri, 06 Nov 2009 17:38:34 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-2658</guid>
		<description>Hi Sun,

Still no luck. I&#039;ve also tested with Eclipse 3.5.1 and it doesn&#039;t work there either. I just left a comment on the Bugzilla entry to see if there&#039;s anything we can do to get this working.

https://bugs.eclipse.org/181508

If you&#039;re really interested in this, you may want to comment on the Bugzilla entry too.

--- Patrick</description>
		<content:encoded><![CDATA[<p>Hi Sun,</p>
<p>Still no luck. I&#8217;ve also tested with Eclipse 3.5.1 and it doesn&#8217;t work there either. I just left a comment on the Bugzilla entry to see if there&#8217;s anything we can do to get this working.</p>
<p><a href="https://bugs.eclipse.org/181508" rel="nofollow">https://bugs.eclipse.org/181508</a></p>
<p>If you&#8217;re really interested in this, you may want to comment on the Bugzilla entry too.</p>
<p>&#8212; Patrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sun</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-2576</link>
		<dc:creator>Sun</dc:creator>
		<pubDate>Thu, 05 Nov 2009 16:34:36 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-2576</guid>
		<description>Hi all,
Any success with fragment based tests under 3.4 ?</description>
		<content:encoded><![CDATA[<p>Hi all,<br />
Any success with fragment based tests under 3.4 ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-517</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Fri, 24 Apr 2009 22:05:36 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-517</guid>
		<description>Hi Gabe,

The collector is pretty simple and could easily be extended to organize tests in different ways. There are no output options right now, though.

To run tests in the IDE, you can just run the test suite that extends the bundle test collector. The tests should run normally in the IDE, but make sure you choose Run As -&gt; JUnit Plug-in Test.

I&#039;ve haven&#039;t been able to run any fragment based tests under the ETF either, at least under 3.4. The fragment doesn&#039;t get activated along with the bundle. Haven&#039;t tried it on 3.5 yet. What version are you using?

--- Patrick</description>
		<content:encoded><![CDATA[<p>Hi Gabe,</p>
<p>The collector is pretty simple and could easily be extended to organize tests in different ways. There are no output options right now, though.</p>
<p>To run tests in the IDE, you can just run the test suite that extends the bundle test collector. The tests should run normally in the IDE, but make sure you choose Run As -&gt; JUnit Plug-in Test.</p>
<p>I&#8217;ve haven&#8217;t been able to run any fragment based tests under the ETF either, at least under 3.4. The fragment doesn&#8217;t get activated along with the bundle. Haven&#8217;t tried it on 3.5 yet. What version are you using?</p>
<p>&#8212; Patrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabe</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-516</link>
		<dc:creator>Gabe</dc:creator>
		<pubDate>Fri, 24 Apr 2009 21:33:37 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-516</guid>
		<description>I am also having a problem where test classes in a fragment are showing a &quot;No tests found&quot; error. I can run the class as an ordinary Junit test just fine. Test classes in a plugin are run fine by BundleTestCollector.</description>
		<content:encoded><![CDATA[<p>I am also having a problem where test classes in a fragment are showing a &#8220;No tests found&#8221; error. I can run the class as an ordinary Junit test just fine. Test classes in a plugin are run fine by BundleTestCollector.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabe</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-515</link>
		<dc:creator>Gabe</dc:creator>
		<pubDate>Fri, 24 Apr 2009 20:21:24 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-515</guid>
		<description>This is great. Thanks!

2 questions:

After creating an AllTests class that extends BundleTestCollector (like shown in the example provided in the zip archive) I cant get it to run as part of my build through ETF but all the tests are shown in a flat list. Can I provide a heirarchy so it is easier to see which tests belong to which package/class?

How can I run directly from the Eclipse IDE?</description>
		<content:encoded><![CDATA[<p>This is great. Thanks!</p>
<p>2 questions:</p>
<p>After creating an AllTests class that extends BundleTestCollector (like shown in the example provided in the zip archive) I cant get it to run as part of my build through ETF but all the tests are shown in a flat list. Can I provide a heirarchy so it is easier to see which tests belong to which package/class?</p>
<p>How can I run directly from the Eclipse IDE?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-514</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 17 Apr 2009 12:04:12 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-514</guid>
		<description>Hi Johannes,

I still run on the junit4 problem with etf. I checked out etf from cvs. Then I exported the etf feature and it seemed to be valid. Of course before I removed every dependency to org.junit and added org.junit4.
But if i run the test target in build.xml I get the message:
...
core-test:
java-test:
     [echo] Running com.rcpquickstart.helloworld.test.collector.AllTests. Result file: E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test/buildDirectory/test/eclipse/results/com.rcpquickstart.helloworld.test.collector.AllTests.xml.
     [java] Java Result: 13
collect-results:
[junitreport] the file E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test\buildDirectory\test\eclipse\com.rcpquickstart.helloworld.test.collector.AllTests.xml is empty.
[junitreport] This can be caused by the test JVM exiting unexpectedly
    [style] Warning: the task name  is deprecated. Use  instead.
    [style] Transforming into E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test\buildDirectory\test\eclipse\results
collect:
[junitreport] the file E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test\buildDirectory\test\eclipse\com.rcpquickstart.helloworld.test.collector.AllTests.xml is empty.
[junitreport] This can be caused by the test JVM exiting unexpectedly
...

Even with debugging I couldn&#039;t find out, what exactly the problem is. Maybe since there is no actual build instruction for etf, can you explain more precisely how you made it.

I would appreciate the help.

Martin</description>
		<content:encoded><![CDATA[<p>Hi Johannes,</p>
<p>I still run on the junit4 problem with etf. I checked out etf from cvs. Then I exported the etf feature and it seemed to be valid. Of course before I removed every dependency to org.junit and added org.junit4.<br />
But if i run the test target in build.xml I get the message:<br />
&#8230;<br />
core-test:<br />
java-test:<br />
     [echo] Running com.rcpquickstart.helloworld.test.collector.AllTests. Result file: E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test/buildDirectory/test/eclipse/results/com.rcpquickstart.helloworld.test.collector.AllTests.xml.<br />
     [java] Java Result: 13<br />
collect-results:<br />
[junitreport] the file E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test\buildDirectory\test\eclipse\com.rcpquickstart.helloworld.test.collector.AllTests.xml is empty.<br />
[junitreport] This can be caused by the test JVM exiting unexpectedly<br />
    [style] Warning: the task name  is deprecated. Use  instead.<br />
    [style] Transforming into E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test\buildDirectory\test\eclipse\results<br />
collect:<br />
[junitreport] the file E:\WS_AutomatedBuildExample\com.rcpquickstart.helloworld.build-and-test\buildDirectory\test\eclipse\com.rcpquickstart.helloworld.test.collector.AllTests.xml is empty.<br />
[junitreport] This can be caused by the test JVM exiting unexpectedly<br />
&#8230;</p>
<p>Even with debugging I couldn&#8217;t find out, what exactly the problem is. Maybe since there is no actual build instruction for etf, can you explain more precisely how you made it.</p>
<p>I would appreciate the help.</p>
<p>Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: com.dmissoh.org &#187; Blog Archive &#187; Nuts and bolts of the UI development: GUI Test of SWT and Eclipse Applications</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-513</link>
		<dc:creator>com.dmissoh.org &#187; Blog Archive &#187; Nuts and bolts of the UI development: GUI Test of SWT and Eclipse Applications</dc:creator>
		<pubDate>Sun, 15 Feb 2009 17:08:48 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-513</guid>
		<description>[...] his article Running Unit Tests for RCP and OSGi Applications, Patrick describes how sets of tests across multiple plug-ins or fragments can be run without using [...]</description>
		<content:encoded><![CDATA[<p>[...] his article Running Unit Tests for RCP and OSGi Applications, Patrick describes how sets of tests across multiple plug-ins or fragments can be run without using [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johannes</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-512</link>
		<dc:creator>Johannes</dc:creator>
		<pubDate>Thu, 29 Jan 2009 18:42:42 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-512</guid>
		<description>Hi Patrick,

no, its surprisingly easy to get this etf running on junit4, just replace all the references in the etf to org.junit with org.junit4. You don´t have to change anything within the SDK (why would you anyway?)

Johannes</description>
		<content:encoded><![CDATA[<p>Hi Patrick,</p>
<p>no, its surprisingly easy to get this etf running on junit4, just replace all the references in the etf to org.junit with org.junit4. You don´t have to change anything within the SDK (why would you anyway?)</p>
<p>Johannes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Markus</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-511</link>
		<dc:creator>Markus</dc:creator>
		<pubDate>Thu, 29 Jan 2009 10:20:59 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-511</guid>
		<description>Hi,

I just would like to give a pointer to an alternative test framework to ETF which is called Autotestsuite and is part of Pluginbuilder.

The Autotestsuite collects both JUnit3 and
JUnit4 Test Cases and creates a test suite automatically. JUnit 3
tests are determined by hierarchy (subclasses of TestCase) whereas
JUnit 4 tests are determined by annotations.

The advantage of the autotestsuite is that you neither need to create
All* suites nor add any XML configuration. Every (except ignored JUnit
4) test will be executed without additional tedious configuration. If
you really want to exclude tests, you can do so with regular
expressions. The regular expressions also provide an easy way to
create conventions for your projects, e.g. *UITest* to execute all UI
specific tests.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I just would like to give a pointer to an alternative test framework to ETF which is called Autotestsuite and is part of Pluginbuilder.</p>
<p>The Autotestsuite collects both JUnit3 and<br />
JUnit4 Test Cases and creates a test suite automatically. JUnit 3<br />
tests are determined by hierarchy (subclasses of TestCase) whereas<br />
JUnit 4 tests are determined by annotations.</p>
<p>The advantage of the autotestsuite is that you neither need to create<br />
All* suites nor add any XML configuration. Every (except ignored JUnit<br />
4) test will be executed without additional tedious configuration. If<br />
you really want to exclude tests, you can do so with regular<br />
expressions. The regular expressions also provide an easy way to<br />
create conventions for your projects, e.g. *UITest* to execute all UI<br />
specific tests.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
