Home > Back-end >  JUnit test keyboard listening in class
JUnit test keyboard listening in class

Time:09-19

I designed a small snake game, also has realized the keyboard monitoring, but also according to the requirement with junit to test the correctness of this keyboard listening, don't know how to use the junit test method to test the bosses can simply tell me about it, I learn
Public void keyReleased (KeyEvent ke) {

The switch (ke getKeyCode ()) {
Case KeyEvent. VK_UP:
If (snake. GetDirection ()!
=2)Snake. SetDirection (0);
break;
Case KeyEvent. VK_RIGHT:
If (snake. GetDirection ()!
=3)The snake. SetDirection (1);
break;
Case KeyEvent. VK_DOWN:
If (snake. GetDirection ()!=0)
The snake. SetDirection (2);
break;
Case KeyEvent. VK_LEFT:
If (snake. GetDirection ()!
=1)The snake. SetDirection (3);
break;
Case KeyEvent. VK_ENTER:
If (SnakeGameView gameState==true) {
SnakeGameView. GameState=false;
} else {
SnakeGameView. GameState=true;
}
break;
Case KeyEvent. VK_ESCAPE:
System.exit(0);
break;
}
}

CodePudding user response:

Detailed test requirements and rules

Then confirm whether to automatic testing
  • Related