Search code examples
javaunit-testingjunitcode-coverage

Are type declarations part of the code coverage information in java projects?


I'm not familiar with code coverage collection in java projects, I have to a task where I should describe the difference between code coverage in python and java.

From my understanding, in python, all type declarations such as method definitions and class definitions, and so on are part of the coverage information (are executed every time by the test case). However, in java, only statements are part of the coverage information is it correct?

For example from the following code snippet only the statement assert(false) will be covered by the test case, as I understood the type declaration public class App extends SuperNew will be not covered the only statement within the superclass are part of the coverage information which is not the case in python.

Example:

public class SuperNew {

    public void magic() {
        assert(false);
    }
}

public class App extends SuperNew {

}

public class Testapp {

    @Test
    public void testApp() 
        new App().magic();
    }
}


Solution

  • The method declaration is not executed and is also already verified by the compiler. -> No, Java code coverage tools do not account for "execution" of declarations.

    In Python it makes a little bit more sense, as no compiler is checking the declarations and they will only be checked at runtime.