TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Software Testing

    Method or Function Coverage

    Overview

    Method or Function Coverage is a metric that checks if each method in the application source code is executed or covered by the tests.

    Method Coverage

    Mathematical formula for Method Coverage is as follows:

    Method Coverage =

    \LARGE \frac{\text{Number of Covered Methods}}{\text{ Total number of Methods}} * 100

    Example

    Sample Method Counters data:

    Covered Methods = 6

    Total Methods  = 8

    Method Coverage = (6/8) * 100

    = 75%

    Missed methods = Total Methods – Covered Methods

    = 8 – 6 = 2 methods.

     

    Code Listing

    Let’s write a simple class with 5 methods. We will execute only some in the code and check the method coverage report in Eclipse IDE. In this example, we will just invoke the methods using the main method.

    public class MethodCoverage {
    
     public void methodOne() {
     System.out.println("methodOne is covered.");
     }
    
     public void methodTwo() {
     System.out.println("methodTwo is covered.");
     }
    
     public void methodThree() {
     System.out.println("methodThree is covered.");
     }
    
     public static void main(String[] args) {
     MethodCoverage mc = new MethodCoverage();
     mc.methodOne();
     }
    
    }

     

    Method Coverage

    Right click on the code editor and choose >> Coverage As >> Java Application. 

    There are 5 methods in the given code. Three user defined instance methods. The main() driver method. One constructor method that is implicitly invoked during the object creation with the new operator.

    The exercised methods are highlighted with green color in the coverage report. The methods that are not exercised are highlighted with red color. We can notice that the methodOne() is covered.

    Covered methods = 3 [ methodOne(), main(), Constructor  method]

    Total methods = 5

    Missed methods = 2 [ methodTwo() , methodThree() ]

    Method coverage = (3/5)*100

    = 60%

    —

    Software Testing Tutorials:

    https://www.testingdocs.com/software-testing-tutorials/

    Related Posts

    Software Testing /

    How can you monitor the Quality Assurance Audit?

    Trends in Software Engineering

    Software Testing /

    Shaping the Future of Development: Exploring Key Trends in Software Engineering

    PuTTY Tool UI

    Software Testing /

    Useful Tools for Software Testers

    Software Testing /

    Mobile Application Testing Challenges

    Errors Code Testing Development

    Software Testing /

    Error Density Metrics

    ‹ Branch Coverage› How to Write Test Cases

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com