Question

I'm trying to create an integration/acceptance testing using FIT. Here is the folder structure:

-src
--main
---fit
----"html files"
---java
----fit
-----"FIT Fixtures files"
----my
-----package
------"business logic files"

Here is my pom.xml (maven2):

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>Test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        ...
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>fit-maven-plugin</artifactId>
            <version>2.0-beta-3</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>fit-maven-plugin</artifactId>
                <version>2.0-beta-3</version>
                <executions>
                    <execution>
                        <configuration>
                            <sourceDirectory>src/main/fit</sourceDirectory>
                            <sourceIncludes>*.html</sourceIncludes>
                            <outputDirectory>${project.basedir}\target</outputDirectory>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        ...
    </repositories>
</project>

Running the FIT test using mvn integration-test -X, I get an error caused by:

java.lang.IllegalStateException: Fixture failed with counts: 0 right, 0 wrong, 0 ignored, 4 exceptions

Still, the FIT output in C:\JavaTest\target\customer-bills.html is generated and contains an error saying: java.lang.RuntimeException: The fixture GivenTheFollowingCustomers was not found.

"GivenTheFollowingCustomers" is the table header in the HTML:

<table>
    <tr>
        <td colspan="3" class="title">GivenTheFollowingCustomers</td>
    </tr>
    ...
</table>

I thought the system would have been looking for the fixture called GivenTheFollowingCustomers? Why it's not able to find it?

Thank you very much!

Update: The system is now able to find the fixture for the first table, but only the first! I was facing the problem because the table header was GivenTheFollowingCustomers instead of fit.GivenTheFollowingCustomers. Still, I'm getting the same error for all the other tables/fixtures in that HTML file. And it's bizarre because it doesn't depend from the specific table. For example, if I move the first table (GivenTheFollowingCustomers) in second position, it stops working and the first one starts working instead. Any clue..?

Update2: I tried to run the tests manually with the FIT library (without maven) and it's working fine! Also, someone else wrote this: http://osdir.com/ml/java.maven-plugins.mojo.user/2007-07/msg00000.html and had no answers. Possible bug in the FIT maven plugin..?

Was it helpful?

Solution

It is a known bug with the FIT maven plugin. The fix should have been released in version 2.0-beta-4 but it has never been released. In fact, it seems like development stopped in December 2007 (ouch!). Anyway, it's possible to solve the problem by creating the following class (as seen in the patch):

/**
 * Extends ColumnFixture to allow a custom ClassLoader to be used for loading fixtures
 * 
 * @author Mauro Talevi
 */
public class ClassLoaderColumnFixture
    extends ColumnFixture
    implements FixtureClassLoaderEnabled
{

    private FixtureClassLoader classLoader;

    public ClassLoaderColumnFixture()
    {
        this( new FixtureClassLoader() );
    }

    public ClassLoaderColumnFixture()
    {
        this( new FixtureClassLoader() );
    }

    public ClassLoaderColumnFixture( FixtureClassLoader classLoader )
    {
        this.classLoader = classLoader;
    }

    public void enableClassLoader( FixtureClassLoader classLoader )
    {
        this.classLoader = classLoader;
    }

    public Fixture loadFixture( String fixtureName )
        throws InstantiationException, IllegalAccessException
    {
        return classLoader.newFixture( fixtureName );
    }
}

And extending from ClassLoaderColumnFixture instead of ColumnFixtures in the fixtures.

This solved my problem, I hope it will be helpful for someone else.

OTHER TIPS

There is a new maven plugin for fit you can use. Just replace the plugin with:

<plugin>
  <groupId>com.github.cradloff</groupId>
  <artifactId>fit-maven-plugin</artifactId>
  <version>3.0</version>
  <executions>
    <execution>
      <id>fixture</id>
      <phase>test</phase>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Then there is no need for a special Class Loader Fixture.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top