簡體   English   中英

使用Maven進行FIT構建失敗

[英]FIT build failure with Maven

我正在嘗試使用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>

使用mvn integration-test -X運行FIT測試,出現以下錯誤:

java.lang.IllegalStateException:夾具失敗,計數: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了問題,因為表頭是GivenTheFollowingCustomers而不是fit.GivenTheFollowingCustomers 不過,對於該HTML文件中的所有其他表/裝置,我仍然遇到相同的錯誤。 這很奇怪,因為它不依賴於特定的表。 例如,如果我將第一個表( GivenTheFollowingCustomers )移到第二個位置,它將停止工作,而第一個開始工作。 有任何線索嗎?

Update2:我嘗試使用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>

這樣就無需特殊的Class Loader夾具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM