2.Testingยง

What is the difference between testing and debugging?

How much time have you already spent on this project testing/debugging your code?

JUnit testing and code coverage

Philosophy

A Bad test (1)

A Bad test (2)

Why is this so bad?
  • It violates our essential rule.
  • There is no testing of what running the program on input DID. Pretty much your only conclusion is that the program did not crash.
  • But worse: Lots of lines of code are "covered". So you don't even know what paths have NOT been tested.

WARNING: Project 2 will be unforgiving of this sort of thing.

Full test of output

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");
}

Selective Testing of Output

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"));
}

What would be good testing for Project 1?

?

Models

What if your model is wrong?

Regression testing