Re: Spindle compatability test suite
Hugo Palma <[email protected]> Wed, 10 May 2006 20:56:31 +0100
| Newsgroups | gmane.comp.ide.eclipse.spindle.devel |
|---|---|
| Message-ID | <[email protected]> |
Forgot to mention how the tested class implementation would be served to
the test class.
I got this working by declaring a hivemind service for each tested class
in spindle-tests and then providing the implementation in the IDE
implementation module. There's also an utility method in
AbstractSpindleTestCase that gets the tested class implementation.
I'm not crazy about having to declare every tested class in the hivemind
descriptor but i couldn't find a better way of doing this.
Hugo Palma wrote:
> I told you i wouldn't let you forget about this :o)
>
> I took advantage of a few dead hours in my day job to give this some
> thought. After some experimenting i came up with some ideas and some
> code also.
>
> There should be a separate module(spindle-tests) with all the
> framework classes and the tests themselves.
>
> The framework consists of one interface, one class and one hivemind
> descriptor. The interface is IFixture, it provides the signature for
> all operations that can be executed in a fixture. A fresh instance of
> the fixture will be provided to each test class at every test run.
> I've come up with the following code for now, still some operations
> missing but good for getting the main picture:
>
> /**
> * A test fixture. Should have an implementation for each IDE.
> */
> public interface IFixture<W, F>
> {
> /**
> * Adds a web root.
> *
> * @param filePath the absolute path to the web root directory.
> * @param relativePath the relative path of the web root. Some
> IDEs let the user specify a different relative path for each web root,
> changing the default "/" path.
> * @return the added web root.
> */
> W addWebRoot(String filePath, String relativePath);
>
> /**
> * Adds a web root with the default "/" relative path.
> *
> * @param filePath the absolute path to the web root directory.
> * @return the added web root.
> */
> W addWebRoot(String filePath);
>
> /**
> * Adds an empty file to a web root.
> *
> * @param webRoot the web root to add the file to.
> * @param path the absolute path of the file to be added.
> * @return the added file.
> */
> F addFileToWebRoot(W webRoot, String path);
>
> /**
> * Adds a source root.
> *
> * @param filePath the absolute path to the source root directory.
> * @return the added source root.
> */
> F addSourceRoot(String filePath);
>
> /**
> * Adds an empty class to a source root.
> *
> * @param root the source root to add the class to.
> * @param packageName the class package.
> * @param className the class name.
> */
> void addClassToSourceRoot(F root, String packageName, String
> className);
>
> /**
> * Adds a .jar file to the classpath.
> *
> * @param jarFile the .jar file to add to the classpath.
> */
> void addJarToClasspath(F jarFile);
>
> /**
> * Adds a file to a source root.
> *
> * @param root the source root to add the file to.
> * @param packageName the package to add the file to.
> * @param fileName the absolute path to the file to be added.
> */
> void addFileToSourceRoot(F root, String packageName, String
> fileName);
>
> /**
> * Tears down the fixture.
> */
> void tearDown();
> }
>
>
> The base class for all tests is also provided. I called it
> AbstractSpindleTestCase. This class provides a getFixture() method to
> every subclass and is responsible for getting the fresh fixture
> instance from Hivemind at every test run. Here's the code i came up with:
>
> /**
> * Base class for all test classes.
> *
> * @author Hugo Palma
> */
> public abstract class AbstractSpindleTestCase extends TestCase
> {
> private IFixture _fixture;
> private static Registry _registry;
>
> {
> _registry = RegistryBuilder.constructDefaultRegistry();
> }
>
> /**
> * {@inheritDoc}
> */
> protected void setUp() throws Exception
> {
> super.setUp();
>
> // Allows getting a brand new IFixture instance every time.
> _registry.cleanupThread();
> _registry.setupThread();
>
> _fixture = (IFixture) _registry.getService(IFixture.class );
> }
>
> /**
> * {@inheritDoc}
> */
> protected void tearDown() throws Exception
> {
> super.tearDown();
>
> // Cleanup the fixture.
> _fixture.tearDown();
> _fixture = null;
> }
>
> protected IFixture getFixture()
> {
> return _fixture;
> }
> }
>
> The only thing missing is the hivemodule.xml in the spindle-tests module:
>
> <module id=" net.sf.spindle.tests" version="1.0.0">
> <service-point id="fixture"
> interface="net.sf.spindle.tests.IFixture"/>
> </module>
>
> So, given this, all the IDE has to do is:
>
> - Create an implementation of the IFixture interface.
> - Provide a hivemodule.xml file in it's spindle-core implementation
> module with something like:
>
> <module id="org.intellij.tapestry" version=" 1.0.0">
> <dependency module-id="net.sf.spindle.tests" version="1.0.0"/>
>
> <implementation service-id="net.sf.spindle.tests.fixture">
> <invoke-factory model="threaded">
> <construct class="org.intellij.tapestry.test.Fixture"/>
> </invoke-factory>
> </implementation>
> </module>
> - Execute the tests. I managed to run the tests from IDEA with no
> problem. I'm going to see how/if i can run tests from a jar file with
> Maven2.
>
>
> Thoughts ?
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642