Method coverage

Code Coverage for Java

Inputs to Procedures

Inputs identify the Java methods executed.

Example

public class Inputs

{

  public static int method()

  {

    return 5;

  }

  public static void main( String[] argv )

  {

    System.out.println("Value:"+method());

  }

}

 

One branch per Java method is defined.

Procedure Inputs, Outputs and Returns, and Terminal Instructions

These include the standard output (if coverable), all return instructions, and calls to exit(), abort(), or terminate(), as well as the input.

Example

public class InputsOutputsAndReturn

{

  public static void method0( int _selector )

  {

    if ( _selector < 0 )

    {

      return ;

    }

  }

  public static int method1( int _selector )

  {

    if( _selector < 0 ) return 0;

    switch( _selector )

    {

      case 1: return 0;

      case 2: break;

      case 3: case 4: case 5: return 1;

    }

    return (_selector/2);

  }

  public static void main( String[] argv )

  {

    method0( 3 );

    System.out.println("Value:"+method1( 5 ));

    System.exit( 0 );

  }

}

 

At least two branches per Java method are defined. The input is always enumerated, as is the output if it can be covered.

Potentially Terminal Statements

The following decision statements are potentially terminal if they contain at least one statement that transfers program control out of its sequence (RETURN, THROW, GOTO, BREAK, CONTINUE) or that terminates the execution (EXIT).

Related Topics

Selecting coverage typesCode Coverage settings