내 뱀 게임용 junit에서 테스트 케이스를 만들려고합니다. 나는 gameover 방법이 있고 나는 그것을 테스트하기 위해 노력하고있어 :그래픽 매개 변수가있는 메소드에 대한 Junit 테스트 케이스
public void gameOver(Graphics g) {
String msg = "Game Over";
final Font small = new Font("Helvetica", Font.BOLD, 14);
FontMetrics metr = this.getFontMetrics(small);
g.setColor(Color.white);
g.setFont(small);
g.drawString(msg, (WIDTH - metr.stringWidth(msg))/2,
HEIGHT/2);
}
내 주요 클래스는 보드이며이 JPanel을 확장합니다. 테스트 :
public void testGameOver() {
System.out.println("gameOver");
Board instance = new Board();
Graphics g = instance.getGraphics();
instance.gameOver(g);
Color tmp = new Color(instance.getBackground().getRGB());
assertEquals(tmp,Color.white.getRGB());
assertEquals(instance.getFont().getFontName(),new Font("Helvetica", Font.BOLD, 14).getFontName());
}
인스턴스에서 gameOver 메소드를 실행하려고하면 java.lang.NullPointerException이 발생합니다. 도와주세요!! 나는 Junit에서 새로운 사람이다.
Testcase: testGameOver(snake.BoardTest): Caused an ERROR
null
java.lang.NullPointerException
at snake.Board.gameOver(Board.java:121)
at snake.BoardTest.testGameOver(BoardTest.java:67)
java.lang.NullPointerException이 포함 된 stacktrace 오류를 게시하십시오. – Scott