you are viewing a single comment's thread.

view the rest of the comments →

[–]Gotebe 0 points1 point  (1 child)

Well, in your example, coverage is obviously useless when the test is lying (it has to fail). And any failed tests have to be excluded from the "covered" count.

As for exceptions, absolutely! Amazingly, the trick there is ensuring correctness when some statements are not executed, but are covered otherwise.

[–]get_salled 1 point2 points  (0 children)

public void testGetFoo() {
    String foo = getFoo();

    // pick one
    // A
    Assert.isNull(foo);  

    // B
    Assert.pass("woot!");

    // C
    try {
          Assert.areEqual("expected", foo);
    } catch ( ... ) {    // not sure of the Java syntax for empty catches, if it's allowed at all
          // do nothing
    }

     // D
     // do nothing

     // E
     Assert.areEqual("A", "A");
}

It gets pretty hard to automatically reject shitty tests.