For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

  • 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

Technology compatibility:

  • Java: Supported from version 4.0.2531 onwards.

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

Technology compatibility:

  • Java: Supported from version 4.0.2531 onwards.

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

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

Coverage Calculation
Overall Method Coverage
Code Changes Coverage
Overall Line Coverage

Default Method Coverage

100%

100%

-

Advanced Method Coverage

33%

50%

-

Line Level Coverage

-

-

43%

Overall Method Coverage

  • 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

Configuration is available to users with Admin or DevOps permissions only.

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.

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.

Last updated

Was this helpful?