2015-10-25 20 views
1

我剛剛安裝了uk.co.javahelp.fitnesse的fitnesse-launcher-maven-plugin,我可以看到它運行良好。爲Maven的fitnesse插件編寫一個測試

現在我想寫一些測試,讓他們看到並在構建過程中執行。

我pom.xml文件包含以下插件:

<profiles> 
    <profile> 
     <id>wiki</id> 
     <build> 
     <plugins> 
      <plugin> 
      <groupId>uk.co.javahelp.fitnesse</groupId> 
      <artifactId>fitnesse-launcher-maven-plugin</artifactId> 
      <version>1.4.2</version> 
      <executions> 
       <execution> 
       <goals> 
        <goal>set-up</goal> 
        <goal>wiki</goal> 
        <goal>tear-down</goal> 
       </goals> 
       </execution> 
      </executions> 
      </plugin> 
     </plugins> 
     </build> 
    </profile> 
    <profile> 
     <id>auto</id> 
     <activation> 
     <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
     <plugins> 
      <plugin> 
      <groupId>uk.co.javahelp.fitnesse</groupId> 
      <artifactId>fitnesse-launcher-maven-plugin</artifactId> 
      <configuration> 
       <failIfNoTests>false</failIfNoTests> 
      </configuration> 
      <executions> 
       <execution> 
       <goals> 
        <goal>set-up</goal> 
        <goal>run-tests</goal> 
        <goal>tear-down</goal> 
        <goal>verify</goal> 
       </goals> 
       </execution> 
      </executions> 
      </plugin> 
     </plugins> 
     </build> 
    </profile> 
    </profiles> 

http://fitnesse-launcher-maven-plugin.googlecode.com 

插件網站文件我也創建下列目錄和空(現在)文件:

[email protected]:toolbox> tree src/test/java/fitnesse/ 
src/test/java/fitnesse/ 
├── FirstTestSuite 
│   ├── content.txt 
│   ├── NestedSuite 
│   │   ├── AnIndividualTest 
│   │   │   ├── content.txt 
│   │   │   └── properties.xml 
│   │   ├── content.txt 
│   │   └── properties.xml 
│   ├── properties.xml 
│   └── Setup 
│    ├── content.txt 
│    └── properties.xml 
└── plugins.properties 

如果運行命令:

mvn verify -P wiki 

然後我就可以在

http://localhost:9123/ 

看到一些默認FitNesse的測試,這些不是我的。

在另一方面,如果我執行命令:

mvn verify 

那麼有沒有要執行的測試:

[INFO] Executed tasks 
[INFO] 
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:run-tests (default) @ toolbox --- 
[INFO] ------------------------------------------------------------------------ 
[INFO] Setting FitNesse variable [maven.classpath] to [ 
!path /home/stephane/dev/java/projects/toolbox/target/test-classes 
!path /home/stephane/dev/java/projects/toolbox/target/classes 
!path /home/stephane/.m2/repository/org/fitnesse/fitnesse/20140201/fitnesse-20140201.jar 
!path /home/stephane/.m2/repository/org/htmlparser/htmlparser/2.1/htmlparser-2.1.jar 
!path /home/stephane/.m2/repository/org/htmlparser/htmllexer/2.1/htmllexer-2.1.jar 
!path /home/stephane/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar 
!path /home/stephane/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar 
!path /home/stephane/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar 
!path /home/stephane/.m2/repository/org/json/json/20090211/json-20090211.jar 
!path /home/stephane/.m2/repository/com/googlecode/java-diff-utils/diffutils/1.2.1/diffutils-1.2.1.jar 
!path /home/stephane/.m2/repository/org/eclipse/jgit/org.eclipse.jgit/2.3.1.201302201838-r/org.eclipse.jgit-2.3.1.201302201838-r.jar 
!path /home/stephane/.m2/repository/com/jcraft/jsch/0.1.46/jsch-0.1.46.jar 
] 
[INFO] Setting FitNesse variable [org.springframework.version] to [4.2.0.RELEASE] 
[INFO] Setting FitNesse variable [java.version] to [1.8.0_60] 
[INFO] Setting FitNesse variable [org.springframework.security.version] to [3.2.5.RELEASE] 
[INFO] Setting FitNesse variable [project.build.sourceEncoding] to [UTF-8] 
[INFO] Setting FitNesse variable [artifact] to [toolbox] 
[INFO] Setting FitNesse variable [version] to [0.0.1-SNAPSHOT] 
[INFO] Setting FitNesse variable [basedir] to [/home/stephane/dev/java/projects/toolbox] 
[INFO] ------------------------------------------------------------------------ 
[WARNING] No FitNesse Suites or Tests to run! (Set -Dfitnesse.fitnesse.failIfNoTests=false to ignore.) 
[INFO] 0 right, 0 wrong, 0 ignored, 0 exceptions 
[INFO] 
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:tear-down (default) @ toolbox --- 
[INFO] 
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:verify (default) @ toolbox --- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 8.061 s 
[INFO] Finished at: 2015-10-26T10:25:17+01:00 
[INFO] Final Memory: 19M/205M 
[INFO] ------------------------------------------------------------------------ 
[email protected]:toolbox> 

我想編寫一個非常簡單的Java測試苗條的夾具,說檢查我的業務邏輯添加(2,2)的方法返回4.

在哪個文件,我應該有我的wiki測試? 我應該在哪個文件夾具中使用? 如何告訴Fitnesse執行我的測試?

UPDATE:我的例子夾具是:

public class ExampleFixture { 

    private String value; 
    private String result; 

    public ExampleFixture() { 
    } 

    public void execute() { 
     if (value != null) { 
      result = Common.trimSpaces(value); 
     } 
    } 

    public void setValue(String value) { 
     this.value = value; 
    } 

    public String getResult() { 
     return result; 
    } 

} 

及其內容:

|Example fixture| 
|value|result?| 
|some space|somespace| 

的最後一個問題,一個關於結果[0]不被發現,是因爲我的getter讀取結果而不是getResult夾具內容,現在顯示爲: |示例夾具| | value | getResult?| | some space | somespace |

+0

你在'http:// localhost:9123/FirstTestSuite'上看到了什麼? – Stewart

+0

嗨斯圖爾特,對於最近的回覆感到抱歉,本週我開始了一項新工作。所以,我用命令:'mvn verify -P wiki'運行了構建,在瀏覽器中我可以看到:'內容: SlimTest TestExample',如果點擊'TestExample',我就會看到:'See .. 示例夾具 值\t結果? \t 部分空間\t somespace'。然後我點擊上面的測試按鈕,它說:'測試執行OK'和'看:示例夾具:壞桌子!表有3個標題列,但第2行只有2列。'。 – Stephane

+0

我現在刪除了一個太多的額外管道,並且進展如下:-)現在說:'com.thalasoft.fitnesse.ExampleFixture'中找不到方法結果[0]。我想知道它在尋找什麼樣的數組類方法...我已經更新了我的問題以顯示夾具類。 – Stephane

回答

1

你已經把src/test/java/fitnesse/

默認位置在你的FitNesse的代碼實際上是:src/test/fitnesse/(刪除java

或者,在你的pom.xml,配置要使用的目錄:

<testResourceDirectory>src/test/fitnesse</testResourceDirectory> 

請參閱Plugin Configuration文檔。

+0

我剛剛注意到路徑問題,通過查看http:// localhost:9123/FirstTestSuite頁面。但是現在將fitnesse目錄移動到默認的src/test/fitnesse位置後,我被重定向到http:// localhost:9123/root?屬性頁面。它看起來像一個屬性頁面,我可以在其中編輯東西。我也可以看到一個鏈接到我的測試套件。 – Stephane

+0

如果運行命令mvn verify然後我得到200的結果響應代碼,但是一個致命錯誤:[致命錯誤]:-1:-1:文件過早結束。 – Stephane

+0

以前從未有過這種行爲。 java-example項目是否適合你? (https://code.google.com/p/fitnesse-launcher-maven-plugin/wiki/Downloads)或者,我所能想到的只是檢查'FirstTestSuite'目錄中的'properties.xml',並檢查FitNesse文檔/ wiki這些錯誤。哪個文件提供「過早結束」? – Stewart