Fitnesse的一個簡單實例

Fixture 代碼java

package eg;
import org.joda.time.DateTime;

public class JodaTime {
    
    int year;
    
    public String getCurrentTime() {
        DateTime dateTime = new DateTime();
        return String.valueOf(dateTime);
      }
    
    public int getYear(){
        DateTime dateTime = new DateTime();
        year = dateTime.getYear();
        return year;
    }
    
    public String getStringYear(){
        DateTime dateTime = new DateTime();
        return String.valueOf(dateTime.getYear());
    }
    
    public String getYearAndMonth(String string){
        DateTime dateTime = new DateTime();
        return String.valueOf(dateTime.getYear()) + String.valueOf(dateTime.getDayOfMonth() + string);
    }
}

 

 table 代碼:測試

!***< Hidden
!*< Classpath setup
!define TEST_SYSTEM {slim}
!path lib/*.jar
*!




'''此處導入後臺代碼包名'''
!|import           |
|eg               |
|fitnesse.fixtures|


*!


'''測試腳本'''
!| script|joda time        |
|check   |get current time||
|check|get year||
|$v=|get year|
|$s=|get string year|
|check | get year and month | 567| |
|check | get year and month | $s| |

 

 table view and result:ui

 

 

-------------------------------------------------------------------------------------------spa

準備工做:命令行

(一)導入第三方jar包,這裏使用到joda-time-2.3.jardebug

1. 先將joda-time-2.3.jar放入到.\fitnesse-master\lib下面code

2. 在Eclipse中按照下圖編輯Build Pathserver

3. 修改FitNesse項目中build.xml文件,以下黃色底部份內容。xml

....
<target name="compile-server" depends="stamp-version, resolve" description="compile FitNesse sources">
        <mkdir dir="${classes.dir}" />
        <ivy:cachepath pathid="compile.classpath" conf="default"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" source="${min.java.version}" target="${min.java.version}" includeantruntime="false" encoding="UTF-8">
            <classpath>
                  <pathelement path = "{lib.dir}/joda-time-2.3.jar"/>
                <path refid="compile.classpath"/>
            </classpath>
        </javac>
        <copy todir="${classes.dir}">
            <fileset dir="${src.dir}">
                <include name="fitnesse/resources/**" />
                <include name="**/*.properties" />
            </fileset>
        </copy>
    </target>
....
 <target name="retrieve" depends="resolve" description="Copy dependencies to lib/, mainly for Acceptance tests and IDE's">
        <!--<delete dir="${lib.dir}" />-->
        <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" conf="standalone,default,test" />
    </target>
....

 4. 在Fitnesse項目的eg下新建JodaTime類,代碼就是上面的Fixture代碼blog

5. 打開命令行,進入Fitnesse主目錄,輸入ant run,進行編譯啓動

6. 在FitNesse中新建一個testpage,點擊Edit按鈕,輸入下圖內容(能夠直接複製上面table代碼)

7.點擊Save後,點擊Test按鈕,開始測試。

相關文章
相關標籤/搜索