2.Testingยง
What is the difference between testing and debugging?
How much time have you already spent on this project testing/debugging your code?
What is the difference between testing and debugging?
How much time have you already spent on this project testing/debugging your code?
Essential rule: Anything that you do in a test must be followed with assertions to verify that what you did is correct.
You want these two to be in alignment.
I see many tests like this:
public void testMInit() {
Memman mem = new Memman();
assertNotNull(mem);
Memman.main(new String[] {"25", "20", "P1SampleInput.txt"});
}
WARNING: Project 2 will be unforgiving of this sort of thing.
public void testSampleInput() throws Exception {
String[] args = new String[3];
args[0]= "10"; args[1]= "32"; args[2]= "P1sampleInput.txt";
Memman.main(args);
assertFuzzyEquals( systemOut().getHistory(),
"|When Summer's Through| " +
"does not exist in the song database.\n" +
"(0,32)\n" +
...
"|Watermelon Man| is added to the song database.\n" +
"(44,11) -> (121,4) -> (319,1)\n");
}
public void testEmpty()
throws Exception {
String[] args = new String[3];
args[0] = "10";
args[1] = "32";
args[2] = "EmptyTest.txt";
System.out.println("Empty test");
Memman.main(args);
assertTrue(systemOut().getHistory().endsWith("(17,47)\n"));
}
?
If you have a model in your head, and you write the program to that model, and you test to that model, a "properly working" program will meet that model.
What if your model does not match reality?