<?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>Fri, 03 Feb 2012 15:37:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Thomas Smith</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-46407</link>
		<dc:creator>Thomas Smith</dc:creator>
		<pubDate>Wed, 14 Dec 2011 20:12:02 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-46407</guid>
		<description>No, the solution above does work on fragments.  I was saying that the bundle test collector doesn&#039;t notice fragments that are not activated, and I&#039;m not sure what the bundle test collector does with full plug-ins that are not activated.</description>
		<content:encoded><![CDATA[<p>No, the solution above does work on fragments.  I was saying that the bundle test collector doesn&#8217;t notice fragments that are not activated, and I&#8217;m not sure what the bundle test collector does with full plug-ins that are not activated.</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-45369</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Thu, 08 Dec 2011 00:59:44 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-45369</guid>
		<description>Hi Thomas,

Maybe I&#039;m not understanding the issue. Are you saying that the solution you referred to above doesn&#039;t work for test fragments? If so, I&#039;d be happy to take a look and see if I can figure something out. I&#039;m currently on vacation, but I&#039;m back next week.</description>
		<content:encoded><![CDATA[<p>Hi Thomas,</p>
<p>Maybe I&#8217;m not understanding the issue. Are you saying that the solution you referred to above doesn&#8217;t work for test fragments? If so, I&#8217;d be happy to take a look and see if I can figure something out. I&#8217;m currently on vacation, but I&#8217;m back next week.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Smith</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-45311</link>
		<dc:creator>Thomas Smith</dc:creator>
		<pubDate>Wed, 07 Dec 2011 19:26:41 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-45311</guid>
		<description>Well, I&#039;m not totally sure about what happens when you have a normal plug-in that&#039;s merely INSTALLED.  But the test collector finds tests that are in fragments by looking in the host plug-ins.  If a fragment is not RESOLVED, it doesn&#039;t make its way into its host&#039;s namespace, and so the test collector doesn&#039;t find it.</description>
		<content:encoded><![CDATA[<p>Well, I&#8217;m not totally sure about what happens when you have a normal plug-in that&#8217;s merely INSTALLED.  But the test collector finds tests that are in fragments by looking in the host plug-ins.  If a fragment is not RESOLVED, it doesn&#8217;t make its way into its host&#8217;s namespace, and so the test collector doesn&#8217;t find it.</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-45144</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Tue, 06 Dec 2011 21:03:53 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-45144</guid>
		<description>Hi Thomas,

Thanks for the tip and for contributing the solution!

--- Patrick</description>
		<content:encoded><![CDATA[<p>Hi Thomas,</p>
<p>Thanks for the tip and for contributing the solution!</p>
<p>&#8212; Patrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Smith</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-45140</link>
		<dc:creator>Thomas Smith</dc:creator>
		<pubDate>Tue, 06 Dec 2011 20:54:44 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-45140</guid>
		<description>Hi,

One problem with this approach is that it&#039;s easy to accidentally skip tests if OSGi fails to load a test plug-in.  I wrote a quick thing that looks at the list of bundles, and finds any that end in &quot;.tests&quot; and are in the &quot;INSTALLED&quot; state, and complains about them.  INSTALLED is bad because plug-ins and fragments need to be a step further, at RESOLVED, before they&#039;re usable.

https://gist.github.com/1439941

It uses tap4j to create a file that lists any missing bundles---that part can be taken out easily if you don&#039;t want it.  I use it with the TAP plug-in for Jenkins, the missing bundles show up as failing tests.

Thanks for this tool, it&#039;s very useful!
-Thomas</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>One problem with this approach is that it&#8217;s easy to accidentally skip tests if OSGi fails to load a test plug-in.  I wrote a quick thing that looks at the list of bundles, and finds any that end in &#8220;.tests&#8221; and are in the &#8220;INSTALLED&#8221; state, and complains about them.  INSTALLED is bad because plug-ins and fragments need to be a step further, at RESOLVED, before they&#8217;re usable.</p>
<p><a href="https://gist.github.com/1439941" rel="nofollow">https://gist.github.com/1439941</a></p>
<p>It uses tap4j to create a file that lists any missing bundles&#8212;that part can be taken out easily if you don&#8217;t want it.  I use it with the TAP plug-in for Jenkins, the missing bundles show up as failing tests.</p>
<p>Thanks for this tool, it&#8217;s very useful!<br />
-Thomas</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-16434</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Tue, 08 Feb 2011 16:49:31 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-16434</guid>
		<description>Hi Vineela,

The bundle test collector can run non-OSGi unit tests just fine, but the tests will run inside of an OSGi container. This can cause issues depending on how your unit tests are structured. For example, if your unit tests are in a separate bundle, they can only access exported packages in the bundle under test. You may also have issues accessing non-public class members. 

Basically, you may encounter any of the problems that commonly occur when you run non-OSGi code inside of an OSGi container...

--- Patrick</description>
		<content:encoded><![CDATA[<p>Hi Vineela,</p>
<p>The bundle test collector can run non-OSGi unit tests just fine, but the tests will run inside of an OSGi container. This can cause issues depending on how your unit tests are structured. For example, if your unit tests are in a separate bundle, they can only access exported packages in the bundle under test. You may also have issues accessing non-public class members. </p>
<p>Basically, you may encounter any of the problems that commonly occur when you run non-OSGi code inside of an OSGi container&#8230;</p>
<p>&#8212; Patrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vineela</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-16410</link>
		<dc:creator>Vineela</dc:creator>
		<pubDate>Tue, 08 Feb 2011 00:23:08 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-16410</guid>
		<description>can bundletestcollector execute non OSGI Junit classes which are written earlier in an OSGI env with out much modification ??</description>
		<content:encoded><![CDATA[<p>can bundletestcollector execute non OSGI Junit classes which are written earlier in an OSGI env with out much modification ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leckie Micka</title>
		<link>http://www.modumind.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/comment-page-1/#comment-16249</link>
		<dc:creator>Leckie Micka</dc:creator>
		<pubDate>Thu, 03 Feb 2011 17:53:55 +0000</pubDate>
		<guid isPermaLink="false">http://rcpquickstart.wordpress.com/?p=71#comment-16249</guid>
		<description>Danke,   endlich habe ich das Problem wirklich kapiert :-)</description>
		<content:encoded><![CDATA[<p>Danke,   endlich habe ich das Problem wirklich kapiert :-)</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

