1

我正在尝试使用 FIT 创建集成/验收测试。这是文件夹结构:

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

这是我的 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>

使用 运行 FIT 测试mvn integration-test -X时,出现以下错误:

java.lang.IllegalStateException: Fixture failed with counts: 0 对,0 错,0 被忽略,4 个异常

尽管如此,仍会C:\JavaTest\target\customer-bills.html生成 FIT 输出并包含一条错误消息: java.lang.RuntimeException: The fixture GivenTheFollowingCustomers was not found.

“GivenTheFollowingCustomers”是 HTML 中的表头:

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

我以为系统会一直在寻找名为GivenTheFollowingCustomers? 为什么它无法找到它?

非常感谢!

更新: 系统现在能够找到第一张桌子的夹具,但只能找到第一张!我遇到了这个问题,因为表头GivenTheFollowingCustomers不是fit.GivenTheFollowingCustomers. 尽管如此,对于该 HTML 文件中的所有其他表/夹具,我仍然收到相同的错误。这很奇怪,因为它不依赖于特定的表。例如,如果我将第一个表 ( GivenTheFollowingCustomers) 移动到第二个位置,它将停止工作,而第一个表开始工作。任何线索..?

Update2:我尝试使用 FIT 库(没有 maven)手动运行测试,它工作正常!此外,其他人写道: http: //osdir.com/ml/java.maven-plugins.mojo.user/2007-07/msg00000.html并没有答案。FIT maven 插件中可能存在的错误..?

4

2 回答 2

1

这是 FIT maven 插件的一个已知错误。该修复程序本应在 2.0-beta-4 版本中发布,但从未发布过。事实上,开发似乎在 2007 年 12 月就停止了(哎哟!)。无论如何,可以通过创建以下类来解决问题(如补丁中所示):

/**
 * 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 );
    }
}

ClassLoaderColumnFixture并从而不是在固定装置中延伸ColumnFixtures

这解决了我的问题,希望对其他人有帮助。

于 2012-03-01T22:19:04.447 回答
0

有一个新的 maven 插件供您使用。只需将插件替换为:

<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>

那么就不需要特殊的类加载器夹具了。

于 2018-01-24T16:36:25.437 回答