Browse Source

created Test for CountFileLine method

master
Leon Montag 2 years ago
parent
commit
77bf7f754c
  1. 41
      src/test/java/game/runGameTest.java

41
src/test/java/game/runGameTest.java

@ -0,0 +1,41 @@
package game;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class runGameTest {
@BeforeEach
void setUp() throws Exception {
}
@Test
public void testCountFileLinesWithThreeLines() {
//arrange
int numLines = 0;
File file;
try {
file = File.createTempFile("temp", ".txt");
FileWriter writer = new FileWriter(file);
writer.write("Zeile 1\n");
writer.write("Zeile 2\n");
writer.write("Zeile 3\n");
writer.close();
//act
numLines = runGame.CountFileLines(file.getAbsolutePath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//assert
assertEquals(4, numLines);
}
}
Loading…
Cancel
Save