編寫測試用例前須要先聲明class或者jar包所在的路徑,才能找到所須要的fixtureide
使用關鍵字path測試
這是使用最多的,每一行表明輸入或者指望輸出,添加?的表明調用的輸出方法,若是指望值和實際輸出值一致,則顯示綠色,不然顯示紅色,而且顯示實際輸出值。若是添加的是()表示返回值,值的顏色是灰色;addRemovePayerFixture在包fixture下,調用的時候須要加上包路徑ui
源碼:this
public class AddRemovePlayerFixture extends ColumnFixture {spa
private String playerName;3d
private Game theGame;orm
public void setPlayerName(final String playerName) {對象
this.playerName = playerName;blog
}繼承
public boolean addPlayer() {
this.theGame = StaticGame.theGame;
Player thePlayer = this.theGame.addPlayer(this.playerName);
return this.theGame.playerIsPlaying(thePlayer);
}
public int countPlayers() {
return this.theGame.getNumberOfPlayers();
}
}
輸入的playerName會調用set方法載入輸入值
用於查詢數據的fixture,只要輸入了查詢的條件就能夠得到返回,也能夠校驗輸出的返回值,這種表格適用於查詢數據
源碼
public class EmployeePayRecordsRowFixture extends RowFixture {
public Object[] query() throws Exception {
EmployeePayRecord[] records = new EmployeePayRecord[2];
records[0] = new EmployeePayRecord(1, 1000, "Bob");
records[1] = new EmployeePayRecord(2, 2000, "Jack");
return records;
}
public Class getTargetClass() {
return EmployeePayRecord.class;
}
}
public class EmployeePayRecord {
public int id;
private double salary;
public String name;
public EmployeePayRecord(final int id, final double salary, final String name) {
this.id = id;
this.salary = salary;
this.name = name;
}
public double pay() {
return this.salary;
}
}
fixture先經過getTargetClass()加載查詢的數據對象,而後經過query得到查詢結果,整個fixture的做用就是組裝數據,
查詢的時候從左往右匹配條件,若是前面的列值沒有找到對應的數據,則會標記爲fail,查詢結果中,沒有指望的值,則會標記爲miss,指望值不在查詢結果中,則會標記爲surplus
當想要操做一系列的方法的時候,能夠使用該fixture
操做的類型主要有三種enter,press,check
enter: 通常適用於set方法,把指望的值傳遞給fixture
press:執行方法,參數可選
check:須要輸入指望值
源碼:
public class CountFixture extends Fixture {
private int counter = 0;
public void count() {
this.counter++;
}
public int counter() {
return this.counter;
}
public void setCounter(final int num) {
this.counter = num;
}
}
當fit提供的fixture不能知足須要的時候,能夠使用table fixture,該fixture能夠自由處理表格單元格的
(0,0)表示左上角第一個單元格
(row,column)都是從0開始
Table fixture的方法
protected abstract void doStaticTable(int rows) |
Table Fixture is an abstract class that you must derive from. You must override doStaticTable to perform the functions of the fixture. The number of rows in the table is passed in rows. |
protected Parse getCell(int row, int column) |
Returns the addressed table cell as a Parse. |
protected String getText(int row, int column) |
Returns the text within the addressed table cell. |
protected boolean blank(int row, int column) |
Returns true if the addressed table cell is blank. |
protected void wrong(int row, int column) |
Turns the addressed table cell red. |
protected void right(int row, int column) |
Turns the addressed table cell green. |
protected void wrong(int row, int column, String actual) |
Turns the addressed table cell red, and annotates it with the actuall value. |
protected void ignore(int row, int column) |
Turns the addressed cell gray. |
protected int getInt(int row, int column) |
Converts the addressed cell to an int, and returns it. |
官網上的例子:http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.FitFramework.TableFixture