Browse Source

Added StudentTest.java file and added test for writeToFile Method for Student class

remotes/origin/fdai7780
fdai7887 11 months ago
parent
commit
0a98db83cd
  1. 28
      src/test/java/org/example/StudentTest.java

28
src/test/java/org/example/StudentTest.java

@ -0,0 +1,28 @@
package org.example;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class StudentTest {
@org.junit.jupiter.api.Test
void writeToFile() throws IOException {
Student student = new Student("Sebastian", "S1001", "Student") ;
String filename = "testStudentData.txt";
student.writeToFile(student, filename);
Path path = Path.of(filename);
String content = Files.readString(path);
assertEquals("Sebastian\nS1001\nStudent", content);
Files.delete(path);
}
}
Loading…
Cancel
Save