Fitnesse的一个简单实例

Fixture 代码

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:

 

 

-------------------------------------------------------------------------------------------

准备工作:

(一)导入第三方jar包,这里使用到joda-time-2.3.jar

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

2. 在Eclipse中按照下图编辑Build Path

3. 修改FitNesse项目中build.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代码

5. 打开命令行,进入Fitnesse主目录,输入ant run,进行编译启动

6. 在FitNesse中新建一个testpage,点击Edit按钮,输入下图内容(可以直接复制上面table代码)

7.点击Save后,点击Test按钮,开始测试。

posted @ 2016-05-31 21:07  月色深潭  阅读(2205)  评论(0编辑  收藏  举报