2012-03-01 190 views
1

我正嘗試使用FIT創建一個集成/接受測試。以下是文件夾結構:用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:Fixture failed with counts:0 right,0 wrong,0 ignored,4 exceptions

儘管如此,產生於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)移到第二個位置,它將停止工作,而第一個表格開始工作。任何線索..?

Update2:我試圖用FIT庫(沒有maven)手動運行測試,它工作的很好!另外,別人寫這個:http://osdir.com/ml/java.maven-plugins.mojo.user/2007-07/msg00000.html並沒有答案。 FIT maven插件中可能存在的錯誤..?

回答

1

這是一個帶有FIT maven插件的known bug。該修補程序應該已在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在燈具延伸。

這解決了我的問題,我希望這會對別人有所幫助。

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> 

然後就不需要特殊的Class Loader Fixture。