這是我第一次不得不寫一個J單元測試,我一直在堅持如何開始。這個課程代表一個奧賽羅板上的單個單元格,它有一個網格和令牌值。JUnit測試一個班級
我想測試「黑色」和「白色」和不同位置的構造函數,我也想測試所有的setters和getters。
任何幫助將不勝感激。
public class BoardCell
{
/**
* The Item at this BoardCell.
*/
private Item token;
/**
* The CellLocation of this BoardCell.
*/
private BoardLocation location;
/**
* Constructor.
* @param row the row number.
* @param col the column number.
* @param token the Item value.
*/
public BoardCell(int row, int col, Item token)
{
this.token = token;
location = new BoardLocation(row, col);
}
/**
* Sets the Item value.
* @param token the Item value.
*/
public void setItem(Item token)
{
this.token = token;
}
/**
* Set the value of the Item in this BoardCell.
* @param val the value of the Item.
*/
public void setValue(String val)
{
this.token.setValue(val);
}
/**
* Gets the Item value.
* @return the Item at this BoardCell.
*/
public Item getItem()
{
return token;
}
/**
* Get the BoardLocation for this BoardCell.
* @return the BoardLocation for this BoardCell.
*/
public BoardLocation getLocation()
{
return location;
}
}
你在使用IntelliJ嗎?如果是這樣,請嘗試突出顯示BoardCell並按住Shift-Ctrl-T。它會爲你建立一個測試。 – rajah9