Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Junit测试,测试构造函数,测试抽象类中的静态数组_Java_Arrays_Junit_Polymorphism_Abstract Class - Fatal编程技术网

Java Junit测试,测试构造函数,测试抽象类中的静态数组

Java Junit测试,测试构造函数,测试抽象类中的静态数组,java,arrays,junit,polymorphism,abstract-class,Java,Arrays,Junit,Polymorphism,Abstract Class,下面我有一个简单的代码。我想测试构造器,看看我的线路板数组是否具有传入的正确行数和列数,以及每个单元格是否为“空”。我该怎么做 public abstract class Game { protected BoardCell[][] board; /** * Defines a board with BoardCell.EMPTY cells. * * @param maxRows * @param maxCols */

下面我有一个简单的代码。我想测试构造器,看看我的线路板数组是否具有传入的正确行数和列数,以及每个单元格是否为“空”。我该怎么做

public abstract class Game {

    protected BoardCell[][] board; 

    /**
     * Defines a board with BoardCell.EMPTY cells.
     * 
     * @param maxRows
     * @param maxCols
     */
    public Game(int maxRows, int maxCols) {
        /*
         * Initialize the static board two-dimensional array with rows and columns
         * equal to that passed in through the parameters.
         */
        this.board = new BoardCell [maxRows][maxCols];

        //Clears each cell in the array.
        for(int i = 0; i < maxRows; i++){
            for(int j = 0; j < maxCols; j++){
                board [maxRows][maxCols] = BoardCell.EMPTY;
            }
        }

    }
}
公共抽象类游戏{
受保护的BoardCell[]]板;
/**
*定义具有BoardCell.EMPTY单元格的板。
* 
*@param maxRows
*@param maxCols
*/
公共游戏(整数maxRows,整数maxCols){
/*
*使用行和列初始化静态板二维数组
*等于通过参数传入的值。
*/
this.board=新的BoardCell[maxRows][maxCols];
//清除数组中的每个单元格。
对于(int i=0;i
创建一个适当的
游戏实例
,然后使用已有的方法在该实例上断言预期结果。我在这里没有看到任何静态或其他问题。但是,您不能为抽象类创建实例。同样,请为您的类创建一个适当的实例。如果您仍然没有任何合适的子类,那么创建一个匿名类(如果这是您想要/需要的),但是您将测试这个匿名类,而不是抽象类。事实上,测试是针对特定类的,而不是针对抽象类/接口的。