User story shows incorrect code coverage.When calculating the coverage of a user story in Copado you might unexpected results. The coverage for a class in the user story is lower than the coverage you see in the source environment for the same class.
There are different ways of checking the code coverage in a Salesforce org and it's important to differentiate between the Overall Code Coverage for a class and the code coverage returned from each method during the test run for the same class.
In the salesforce org you might see that a class has Overall Code Coverage of 90% but when running the test class for that class in a user story in Copado, the coverage returned is 50%. That is most likely because the methods in the test class in the user story are covering only 50% of the code in the class. The rest of the code is covered by methods in other test classes.
You can see what other methods might be covering the code for a specific class in the source environment. As explained in the Salesforce article below:
From the Developer Console, to view line-by-line code coverage for an Apex class, open the class. The Code Coverage menu will include one or more of the following options depending on the tests you have implemented:
- All Tests: The percentage of code coverage from all test runs.
- className.methodName: The percentage of code coverage from a method executed during a test run.
You should be able to see the className.methodName covering the code in your class. If you see methods from other test classes not included in your user story, that will explain the reason why you are not seeing the same coverage as the Overall Code Coverage you see in the source environment for that class.