Menu

#81 coverage info missing prior catch block

open
REPORTS (28)
5
2007-05-11
2007-05-11
No

I'm running emma on a unit test, and it seems that emma reports no coverage in some function _prior_ to a catch block that the code enters

see the attached report HTML document.

it is clear, that all line before the catch block are actually executed in functions testRemoveAllEntities() and testRemoveEntity() - even though they are reported with red color by emma

Discussion

  • Ákos Maróy

    Ákos Maróy - 2007-05-11

    emma generated coverage report

     
  • Per Lundholm

    Per Lundholm - 2007-05-23

    Logged In: YES
    user_id=310871
    Originator: NO

    I also have run into this.

    The pattern seems to be

    W public void test_method() {
    R (code block 1)
    W try {
    R (try block)
    G } catch (Exception e) {
    G (catch block)
    W }
    G }

    W=White, G=Green, R=Red.

     
  • Marcio Mazza

    Marcio Mazza - 2007-08-05

    Logged In: YES
    user_id=1860893
    Originator: NO

    It seems that the problem has something to do with calling JUnit method
    "void org.junit.Assert.fail(String message)"

    A test to illustrate:

    -----------------------------------------------------------------------
    public class EmmaBugTest {

    // WRONG
    @Test
    public void testCoverageBugWithFail() {
    System.out.println("with fail: BEFORE TRY"); // RED
    try {
    System.out.println("with fail: TRY"); // RED
    fail("failed"); // RED
    } catch (AssertionError e) { // GREEN
    System.out.println("with fail: " + e); // GREEN
    }
    }

    // WRONG
    @Test
    public void testCoverageBugWithAssert() {
    System.out.println("with assertTrue: BEFORE TRY"); // RED
    try {
    System.out.println("with assertTrue: TRY"); // RED
    assertTrue(false); // RED
    } catch (AssertionError e) { // GREEN
    System.out.println("with assertTrue: " + e); // GREEN
    }
    }

    // RIGHT
    // with "-ea" VM argument
    @Test
    public void testCoverageBugAssertion() {
    System.out.println("with raw assert: BEFORE TRY"); // GREEN
    try {
    System.out.println("with raw assert: TRY"); // GREEN
    assert false : "ASSERTION FAILED"; // GREEN
    } catch (AssertionError e) { // GREEN
    System.out.println("with raw assert: " + e); // GREEN
    }
    }

    // RIGHT
    @Test
    public void testCoverageBugAssertionError() {
    System.out.println("with AssertionError: BEFORE TRY"); // GREEN
    try {
    System.out.println("with AssertionError: TRY"); // GREEN
    throw new AssertionError("AssertionError"); // GREEN
    } catch (AssertionError e) { // GREEN
    System.out.println("with AssertionError: " + e); // GREEN
    }
    }
    }

    -----------------------------------------------------------------------
    SYSTEM OUTPUT:

    with fail: BEFORE TRY
    with fail: TRY
    with fail: java.lang.AssertionError: failed
    with assertTrue: BEFORE TRY
    with assertTrue: TRY
    with assertTrue: java.lang.AssertionError:
    with raw assert: BEFORE TRY
    with raw assert: TRY
    with raw assert: java.lang.AssertionError: ASSERTION FAILED
    with AssertionError: BEFORE TRY
    with AssertionError: TRY
    with AssertionError: java.lang.AssertionError: AssertionError

     

Log in to post a comment.