> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/intro-to-sealights/technical-overview/coverage-calculation.md). Agents can also search and read this documentation through its [MCP server](https://docs.sealights.io/knowledgebase/~gitbook/mcp).

# Coverage Calculation

## Method-Level Coverage

Code coverage is a crucial metric for software development, measuring the portion of your code that gets executed during testing. SeaLights provides two coverage metrics on a method level:&#x20;

* **Overall Coverage:** Percentage of methods tested by at least one test stage.
* **Code Changes Coverage:** Percentage of changed methods tested by at least one test stage.

SeaLights offers two prominent method-level coverage calculation approaches: **default method coverage** and **advanced method coverage**.

### **Default Method Coverage**

Default method coverage is a straightforward approach that focuses on a fundamental question: **Was a particular method invoked at least once** during the test execution? Default coverage simply verifies if the test suite triggered this method to execute, regardless of how much code within the method was actually exercised. This approach provides a basic indication of whether the method was part of the testing process, but it doesn't offer any insight into the specific lines of code that were executed.

### **Advanced Method Coverage**

{% hint style="info" %}
Technology compatibility:

* **Java:** Supported from version 4.0.2531 onwards.
  {% endhint %}

Advanced method coverage takes code coverage a step further by providing a more granular view of test effectiveness. It goes beyond simply knowing if a method was called and instead calculates the **percentage of lines of code within the method that were actually executed** during testing. This allows you to define a **coverage threshold**, a specific percentage (e.g., 80%) that a method's executed lines must meet to be considered adequately covered. Methods exceeding this threshold demonstrate that a significant portion of their code was exercised during testing, boosting confidence in their functionality.

#### **Advanced Coverage Nuances: Handling Short Methods**

Advanced coverage excels for methods with a substantial number of lines. Therefore, you can define a minimum number of lines a method must have in order to use the advanced coverage calculation. For methods shorter than this threshold, SeaLights will **default back** to the simpler approach of checking if the method was called at all. This is because calculating a percentage coverage for a very short method might not be very meaningful.

#### **Important Notes**

Enabling advanced coverage can **impact performance** during testing. This is because SeaLights needs to track the execution of each line of code within a method. The impact might be negligible for small projects, but for larger codebases, it's something to consider. Advanced coverage is also **limited to analyzing code within methods**. It cannot track coverage for code outside methods, such as global variables or code blocks.

#### **Understanding Method Level Coverage Limitations**

While advanced coverage provides valuable insights, it's crucial to understand its limitations regarding specific line coverage and change awareness. SeaLights **does not track changes between builds on a line level**. This means it cannot pinpoint which exact lines within a method were modified. Therefore, a method might show 80% coverage, but the recent code changes could have impacted the uncovered 20% of lines.

#### **SeaLights On-Prem Utility for Detailed Code Change Analysis (Coming Soon)**

To analyze code changes and coverage on a granular level, SeaLights offers a dedicated on-premise utility that generates an XLSX file. This file provides valuable insights for specific app/branches/build.\
The utility compares code changes between a reference build and the current build, allowing users to see changes and coverage per line.

By leveraging this utility and understanding the strengths and limitations of method-level coverage, you can ensure your critical code areas are thoroughly tested and identify potential risks associated with unverified code changes.

### **Choosing the Right Method Coverage Approach**

The best approach for your project depends on your specific testing goals, the complexity of your codebase, and your performance requirements. The setting for selecting default or advanced coverage is configured at the **application level** within SeaLights. Here's a breakdown to help you decide:

* **Default Method Coverage:**
  * Ideal for initial testing phases where a basic understanding of method invocation is sufficient.
  * Provides a quick overview of which methods are being exercised in your test suite.
  * Well-suited for simpler projects with less intricate code or for scenarios where performance is a critical concern.
* **Advanced Method Coverage:**
  * Invaluable for ensuring thorough testing and identifying areas where code might not be adequately exercised.
  * Offers a more comprehensive view of test effectiveness by analyzing the percentage of executed lines within a method.
  * Essential for complex projects with intricate code logic, where ensuring comprehensive coverage is critical. However, be mindful of the potential performance impact.

#### **In Conclusion**

Both default and advanced method coverage play vital roles in your testing strategy. Understanding their strengths and limitations allows you to choose the right approach for your project. Default coverage provides a starting point, while advanced coverage offers deeper insights. Consider using advanced coverage with a defined threshold for thorough testing and identifying areas for improvement in your test suite. By leveraging these coverage approaches effectively, you can build robust and reliable software with confidence.

***

## Line-Level Coverage

{% hint style="info" %}
Technology compatibility:

* **Java:** Supported from version 4.0.2531 onwards.
  {% endhint %}

Beyond method-level coverage metrics (Overall Coverage and Code Changes Coverage), SeaLights offers a complementary line-level coverage metric: Overall Line Coverage.

This metric takes a more granular approach, calculating the percentage of **executable lines within methods** that were executed during **any testing stage**. It provides a broader view of how thoroughly your test suite exercises the code across your entire application.

#### **Understanding Line Coverage in SeaLights**

Here are some key points to consider when interpreting Overall Line Coverage in SeaLights:

* **Limited Scope:** Overall Line Coverage only considers lines of code that reside **within methods**. Code outside methods, such as global variables or code blocks, is not included in this calculation.
* **Potential Discrepancies:** The Overall Line Coverage value you see in SeaLights might differ from what other code coverage tools like SonarQube or JaCoCo report. This is because these tools might employ different coverage calculation methods or include non-method code in their analysis.
* **Performance Impact:** Enabling Overall Line Coverage, similar to Advanced Method Coverage, can impact performance during testing. This is because SeaLights needs to track the execution of each line of code within a method. The impact might be negligible for small projects, but for larger codebases, it's something to consider.

By understanding these considerations, you can effectively leverage Overall Line Coverage alongside method-level metrics for a more comprehensive assessment of your testing effectiveness.

***

## Coverage Calculation Comparison&#x20;

This table summarizes code coverage metrics for an app with three methods (A, B, and C) using Default, Advanced, and Line Level Coverage approaches, assuming a 75% threshold and a 5-line minimum for advanced coverage.

* Method A: 10 lines, 2 changed, 8 covered
* Method B: 10 lines, 1 changed, 2 covered
* Method C: 10 lines, 0 changed, 3 covered

<table><thead><tr><th>Coverage Calculation</th><th>Overall Method Coverage</th><th width="199">Code Changes Coverage</th><th>Overall Line Coverage</th></tr></thead><tbody><tr><td>Default Method Coverage</td><td>100%</td><td>100%</td><td>-</td></tr><tr><td>Advanced Method Coverage</td><td>33%</td><td>50%</td><td>-</td></tr><tr><td>Line Level Coverage</td><td>-</td><td>-</td><td>43%</td></tr></tbody></table>

#### Overall Method Coverage&#x20;

* Default Method Coverage = 100% (3/3 methods)
  * Method A was invoked = Method covered
  * Method B was invoked = Method covered
  * Method C was invoked = Method covered
* Advanced Method Coverage = 33% (1/3 methods)
  * Method A has 80% line coverage = Method covered
  * Method B has 20% line coverage = Method uncovered
  * Method C has 30% line coverage = Method uncovered

#### Advanced Method Coverage

* Default Method Coverage = 100% (2/2 methods)
  * Method A was invoked = Method covered
  * Method B was invoked = Method covered
  * Method C has no code changes
* Advanced Method Coverage = 50% (1/2 methods)
  * Method A has 80% line coverage = Method covered
  * Method B has 20% line coverage = Method uncovered
  * Method C has no code changes

#### Overall Line Coverage

* Line Level Coverage = 43% (13/30 lines)
  * Method A has 8 lines covered = 8
  * Method B has 2 lines covered = 2
  * Method C has 3 lines covered = 3

#### Detailed Breakdown

Similar view will be available as part of SeaLights' on-prem utility.

| Method   | Line | Changed | Covered |
| -------- | ---- | ------- | ------- |
| Method A | 1    | Yes     | Yes     |
| Method A | 2    | No      | Yes     |
| Method A | 3    | No      | No      |
| Method A | 4    | No      | Yes     |
| Method A | 5    | Yes     | Yes     |
| Method A | 6    | No      | Yes     |
| Method A | 7    | No      | Yes     |
| Method A | 8    | No      | Yes     |
| Method A | 9    | No      | Yes     |
| Method A | 10   | No      | No      |
| Method B | 1    | Yes     | No      |
| Method B | 2    | No      | Yes     |
| Method B | 3    | No      | Yes     |
| Method B | 4    | No      | No      |
| Method B | 5    | No      | No      |
| Method B | 6    | No      | No      |
| Method B | 7    | No      | No      |
| Method B | 8    | No      | No      |
| Method B | 9    | No      | No      |
| Method B | 10   | No      | No      |
| Method C | 1    | No      | Yes     |
| Method C | 2    | No      | Yes     |
| Method C | 3    | No      | Yes     |
| Method C | 4    | No      | No      |
| Method C | 5    | No      | No      |
| Method C | 6    | No      | No      |
| Method C | 7    | No      | No      |
| Method C | 8    | No      | No      |
| Method C | 9    | No      | No      |
| Method C | 10   | No      | No      |

***

## **Seamless Configuration on the New Coverage Dashboard**

{% hint style="info" %}
Configuration is available to users with Admin or DevOps permissions only.&#x20;
{% endhint %}

These powerful features **are conveniently accessible on an app/branch level on our new coverage dashboard.** Simply click the coverage settings button on the relevant app/branch you want to manage to configure these options. Please note that these **settings are not applicable for integrations builds**, as coverage calculation is defined on each app/branch (component) separately.

<div><figure><img src="https://1255034336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxSagdStwf6CJ9cI6lA68%2Fuploads%2FbbupelH6qxNlgBaYiSyB%2FScreenshot%202024-07-04%20at%2013.26.46.png?alt=media&amp;token=7b3d3763-6bc0-4b07-a832-045ed04d8577" alt=""><figcaption></figcaption></figure> <figure><img src="https://1255034336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxSagdStwf6CJ9cI6lA68%2Fuploads%2FXbEalJOUEtlKfUhMnWYT%2FScreenshot%202024-07-04%20at%2013.26.34.png?alt=media&amp;token=8f33cad2-1cb0-4bf9-987a-12fffdaf42b7" alt=""><figcaption></figcaption></figure> <figure><img src="https://1255034336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxSagdStwf6CJ9cI6lA68%2Fuploads%2FUPuCZXFN1kG6UAI0zvOW%2FScreenshot%202024-07-04%20at%2012.54.52.png?alt=media&amp;token=28626175-10a6-40ca-88ed-b8f0da553ab6" alt=""><figcaption></figcaption></figure></div>

#### **Understanding Your Build Calculation**

Unsure how your build's code coverage was calculated? **Simply click on the info icon to view the details.** This icon provides a quick and easy way to understand the specific calculation method used for your build.

<figure><img src="https://1255034336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxSagdStwf6CJ9cI6lA68%2Fuploads%2FU8Lnq2D7uJAvaugJYTzf%2FScreenshot%202024-07-04%20at%2013.29.22.png?alt=media&amp;token=bcc700d8-e9c4-49b8-b801-be66ca9145dc" alt="" width="375"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sealights.io/knowledgebase/intro-to-sealights/technical-overview/coverage-calculation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
