我需要使用 JUnit 来测试我编写的一些方法。当我去创建一个测试类并编写一个测试方法时,IntelliJ运行了整个程序(包括main方法),还没有完成。我只想测试一个方法,为此,我已经按照说明 (Ctrl+Shift+F10) 或方法附近的绿色小播放按钮(如果愿意)完成了。尽管如此,它总是运行整个代码,并给我错误,而不是我想测试的方法。
class QueensTest {
@Test
void testCreate() {
assertNotNull(Queens.create(4));
assertThrows(IllegalArgumentException.class, () -> Queens.create(-1));
}
}
这是我想测试的方法,它给了我这个错误。
java: cannot find symbol
symbol: variable TODO
location: class at.jku.ssw.queens.app.QueensMain
如果有帮助,我可以发布整个代码(所有类)。
导致错误的代码:
public static void main(String[] args) throws Exception {
Out.print("Waehle Groesse: ");
int n = In.readInt();
Queens game = TODO;
Out.println();
printBoard(game);
boolean terminate = false;
while (TODO) {
Out.println();
Out.print("Waehle Setzen (S) | Entfernen (E) | Clear (C) | Quit (Q): ");
char cmd = Character.toUpperCase(In.readChar());
if (cmd == 'S') {
Out.print("Setze Queen auf Zeile: ");
int row = In.readInt();
Out.print(" Spalte: ");
char col = Character.toUpperCase(In.readChar());
// TODO
} else if (cmd == 'E') {
Out.print("Entferne Queen von Zeile: ");
int row = In.readInt();
Out.print(" Spalte: ");
char col = Character.toUpperCase(In.readChar());
// TODO
} else if (cmd == 'C') {
// TODO
} else if (cmd == 'Q') {
terminate = true;
} else {
Out.println("Ungueltiges Kommando!");
}
}
}
private static void printBoard(Queens game) throws Exception {
Out.print(" |");
for (int col = 0; col < game.getSize(); col++) {
Out.print(String.format(" %c ", (char)('A' + col)));
}
Out.println("|");
Out.print("---|");
for (int col = 0; col < game.getSize(); col++) {
Out.print("---");
}
Out.println("|");
for (int row = 1; row <= game.getSize(); row++) {
Out.print(String.format(" %d |", row));
for (int col = 0; col < game.getSize(); col++) {
Out.print(TODO ? " Q " : " . ");
}
Out.println("|");
}
Out.print("---|");
for (int col = 0; col < game.getSize(); col++) {
Out.print("---");
}
Out.println("|");
Out.println();
Out.println("Stand: " + TODO);
}