In Summer 15 release, Salesforce changed the way to calculate code coverage for multiline statements. As a developer, you feel good in some situation and bad in some situations. In this post, I will explain both the situations.
Let me first explain the change –
If a single statement is broken into multiple lines, then each line will be considered now while calculating the code coverage. To be more precise, each line that contains an expression will be considered while calculating code coverage. Before Summer 15 release, multiline was considered as a single line.
To explain more, I will start with a simple code snippet.
Situation 1 – Happy Situation:
Consider the below code snippet.
Now say for example, you have written unit test methods for the methods calculateDistanceBetweenAB(), calculateDistanceBetweenBC(), calculateDistanceBetweenCD() and calculateDistanceBetweenDA().
You have also written test methods to cover line# 8,9 and 10. The only line which is not covered/tested is line# 11.
Now before Summer 15 release, the way in which code overage was calculated –
Total number of lines = 4 (line # 3,8,9 and 11)
Total number of lines covered = 3 (line # 3,8 and 9)
So the code coverage = 3/4 i.e. 75%
But after Summer 15 release, the way in which code overage will be calculated –
Total number of lines = 7 (line # 3,4,5,6,8,9 and 11)
Total number of lines covered = 6 (line # 3,4,5,6,8 and 9)
So the code coverage = 6/7 i.e. 85%
As you can see that the code coverage increases here. So for me, this is a happy situation.
Situation 2 – Not So Happy Situation:
Consider the same code snippet.
Now say for example, you have written unit test methods for the methods calculateDistanceBetweenAB() only.
You have also written test methods to cover line# 8,9 and 10.
Now before Summer 15 release, the way in which code overage was calculated –
Total number of lines = 4 (line # 3,8,9 and 11)
Total number of lines covered = 3 (line # 3,8 and 9)
So the code coverage = 3/4 i.e. 75%
But after Summer 15 release, the way in which code overage will be calculated –
Total number of lines = 7 (line # 3,4,5,6,8,9 and 11)
Total number of lines covered = 3 (line # 3,8 and 9)
So the code coverage = 3/7 i.e. 42%
So this is not so happy situation as you can see that code coverage decreases here. But there is always a way. You can write more test methods to increase the code coverage.
Please check the below details for your reference –
About The Author
Related Posts
2 Comments
Leave a reply Cancel reply
Recent Posts
- How To Create Pods And Check Pod Health In Kubernetes
- How To Bind Variables in Dynamic SOQL Query in Salesforce
- How To Secure Apex Code With User Mode Database Operations | Spring 23 Release
- How To Find Out Which Apex Classes Implement The Interface | Spring 23 Release
- Salesforce Summer 23 Release Information
Apex Architect array Async attribute B2B B2C Best Practices combinator css css3 dense array Developer development Enhanced Domain Flow Google Cloud Google Cloud Certification Google Cloud Digital Leader Google Cloud Platform group husky ide JavaScript Kubernetes Loyalty Management Pod Promises pseudo-class pseudo-elements Release Salesforce Salesforce Certification scope Security selectors SOQL sparse array specificity specificity-rules Spring 23 TypeScript Virtual Machine vscode web
Recent Comments
Archives
2023
- February 24 Salesforce Summer 23 Release Information
- February 20 How to Run Kubernetes Locally in Docker Desktop
- February 8 Basics of Kubernetes Architecture
- January 9 Salesforce Flow Best Practices
- January 3 10 Apex Programming Best Practices
2022
- December 12 Setup Loyalty Program in Salesforce
- December 1 Introduction to Dart Programming
- November 23 How to Pass Salesforce Certified Associate Exam
- November 14 How do I setup a static IP with Google Cloud?
- August 26 TypeScript Setup
- August 25 Introduction to TypeScript
- April 18 JavaScript Void Operator
- January 12 Understand Regions and Zones in Google Cloud
- January 10 How To Start With Google Cloud
2021
- October 26 Top JavaScript Console Features
- October 14 Summer ’21 Flow New Features
- October 14 Events in JavaScript
- April 20 Understand JavaScript Closure
- April 15 Functions in JavaScript
- March 31 Sorting Arrays in JavaScript
- March 3 Dynamic Action in Salesforce
- March 2 Dynamic Form in Salesforce
- February 18 How to Query Multi-Currency Fields in Salesforce
- January 5 Top Admin Features from Spring 21
2020
- December 28 Top Apex Features From Spring 21
- December 25 It’s Christmas Time!!! Happy ho-ho- holidays!
- November 16 Truncate Custom Objects in Salesforce
- October 13 Dataloader for Salesforce
- October 12 Send Custom Notifications Using Apex
- September 22 Using Apex with Knowledge
- September 21 Handy SOQL/SOSL Queries for Knowledge
- September 17 Understand Salesforce Lightning Knowledge Data Model
- September 16 Queueable Apex
- September 14 New Admin Features From Winter 21 Release
- September 7 How to update “N” records in Flow
- August 26 Winter ’21 Apex New Feature
- August 25 Winter ’21 Flow Enhancements
- February 7 Dreamforce 2019 Global Gathering
- January 9 Compare Knowledge Articles – WoW Feature
2019
- July 26 All About Asynchronous Apex
- February 10 Understanding JavaScript Promises
2018
- December 28 Happy New Year and Keep Learning
- October 1 Getting Started with Salesforce DX
- September 10 Getting Started with Financial Services Cloud
- February 3 LastModifiedDate Vs SystemModStamp
2017
- February 25 Salesforce Optimizer – Spring 17 New Feature
- January 23 Product Schedule in Salesforce
- January 22 Products and Price Books in Salesforce
- January 18 Delegate Administrator
- January 15 JavaScript Tips for Visualforce Developers
2016
- December 7 All about Git – “Git Stash” Part – II
- December 6 All about Git – Cheat Sheet – Basic Part – I
- October 1 Dynamic Apex – Playing with CRUD and FLS
2015
- August 11 APEX TRIGGER DESIGN PATTERN
- July 19 DYNAMIC VISUALFORCE BINDINGS
- February 5 Spring ’15 – New Feature Added – @testSetup
- January 30 Google Polymer – Override Style
- January 29 Types of Chart for Dashboard in Salesforce
- January 29 Types of Report in Salesforce
- January 26 Google Polymer – First Hello World Component
- January 25 Google Polymer – How to Install
- January 25 Ideas in Salesforce
- January 23 Solution Management in Salesforce Part I
- January 10 Campaign in Salesforce and Security involved
- January 10 Admin Notes — Licenses in Salesforce
- January 3 Integrating jQuery with Visualforce
- January 1 Happy New Year 2015 !!!!
2014
- November 17 How Salesforce Does Agile
- November 17 Winter ’15 Release-Overview and Highlights
- October 31 Different Chatter Licenses in Salesforce
- October 31 Standard Chatter Profiles in Salesforce
- October 31 Standard Profiles available in Salesforce
- October 26 Diwali 2014
- October 17 JSON2Apex – Convert JSON Into Apex Class
- October 15 Custom Logging Framework in Salesforce
- October 7 Before Delete Trigger in Salesforce
Nice write-up! Thanks for sharing.
You welcome Robert Strunk