Это первый раз, когда мне пришлось написать J Unit Test, и я зациклился на том, как начать работу. Этот класс представляет собой одну ячейку на плате Othello, у которой есть значение сетки и токена.JUnit Тестирование класса
Я хотел протестировать конструктор как с «черным», так и «белым» и разными местоположениями, и я также хотел протестировать все сеттеры и геттеры.
Любая помощь была бы принята с благодарностью.
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