我正在尝试使用 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:固定装置失败了:0 条正确,0 条错误,0 条忽略,4 条例外

尽管如此,FIT 输出 C:\JavaTest\target\customer-bills.html 已生成并包含错误: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)在第二个位置时,它停止工作,第一个位置开始工作。有什么线索吗..?

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

有帮助吗?

解决方案

它是一个 已知错误 使用 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 在赛程中。

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

其他提示

有一个新的 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>

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top