I have a method that writes to a file with a given name. Do I have to test this method and, if so, for what should I test it?
public void record(Object o){
try{
FileWriter fileStream = new FileWriter("data.txt", true);
BufferedWriter out = new BufferedWriter(fileStream);
out.write(o.toString());
out.newLine();
out.close();
} catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
Whether you have to test is or not is a question for your project lead. If it’s determined you should write some tests, then I would test at least these cases