samedi 12 octobre 2019

how to test this class with JUnit testing?

I have TicTacToe game in java language and I have to do Junit test cases for this Game class, because I need to apply mutation testing for this application. can anyone help me to write good test cases.

public class Game {
private Board board;
private Queue<Player> players;

public Game() {
    board = new Board();
    players = new LinkedList<>();

    addPlayers();

}

private void addPlayers() {
    players.add(new Player("X"));
    players.add(new Player("O"));
}


private void startGame() throws IOException {
 do {
     Player currentPlayer = players.remove();
     System.out.println("Enter position for Player "+currentPlayer.toString());

     java.io.BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

     board.placeMarker(currentPlayer,new Position(Integer.parseInt(in.readLine()),Integer.parseInt(in.readLine())));
     players.add(currentPlayer);
     System.out.println(board.toString());
     if(board.hasWon(currentPlayer)){
         break;
     }
 }while (board.hasEmptyPosition());
}




public void main(String[] args) {
    Game game= new Game();
    try {
        game.startGame();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

Aucun commentaire:

Enregistrer un commentaire