function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
adreameradreamer 

Test coverage discrepancy between Force.com IDE and Salesforce online UI

Hi All,

 

I am seeing a substantial difference in the test coverage between the results in Eclipse and the results of Salesforce online UI.

 

Here is a concrete example. A controller class when running the test for it in Eclipse I get 99% coverage and only 3 lines are not covered.

 

On the other hand, when I run all test from Salesforce online UI (Setup | App Setup | Classes and using the Run All Test button) I get for the same class only 59% coverage. Moreover, if I click on this class and run the test for that class in Salesforce I still get 59%.

 

Has anybody seen something like this ?

 

Regards,

Fernando

Best Answer chosen by Admin (Salesforce Developers) 
Chris JohnChris John

This appears to be resolved for me, is anybody still experiencing this issue? If so, it may be worth attempting to clear your test results as follows:

 

1. Setup > Develop > Apex Test Execution

2. View Test History

3. Clear Test Results

All Answers

Andy Freeston_LarterAndy Freeston_Larter

Yes. I had the same problem this week. I had expected the online test to show either the same or higher coverage since it was testing all the methods where as I was only testing classes individually from Eclipse. The online tests shows much lower coverage.

adreameradreamer

Hi Andy,

 

Thank you for your input.

 

Looking at it closely here are more details that might help.

 

1. The overall test coverage accross all classes/triggers is the same in Eclipse and Salesforce online UI.

2. Looking at what is not covered using the Salesforce online UI and Eclipse, the latter is right whereas the former is not. This might explain why the individual coverage for each class is much lower in the Salesforce online UI.

 

So the way I am using the tools is as follows:

a. I develop the testing code in Eclipse working on each class individially and looking at the test coverage for the class there. Once I get the 100% (almost) I considered done.

b. When I want to see the overall test coverage accross all classes I look at Eclipse or Salesforce online UI, it does not matter because are the same. I disregard the coverage results of individual classes in Salesforce online UI.

 

Regards,

Fernando

Andy Freeston_LarterAndy Freeston_Larter

I have been using the same technique. I just hope I don't run into problems when I deploy the code to my production org.

 

Just so show what I can see, I have included the coverage data from my code:

   Web UI Eclipse
BasketDetails 85% 91%
LicenceDetails 87% 89%
LicenceReader 94% 95%
LicenceTesting 91% 90%
PaymentBatcher 64% 87%
PaymentList 100% 100%
PaymentScheduler 100% 100%
PurchaseError 88% 88%
PurchaseFuncs 90% 91%
PurchaseLicence 0% 0%
PurchaseResult 61% 62%
SessionData 96% 97%



Most of the results look close (probably different due to rounding). I can't explain why PaymentBatcher is so different though.

adreameradreamer

In the Salesforce online UI, if you click on the coverage for an individual class, a screen pops up with the code highlighted. The light blue is what is covered by the test methods and the red ones are those that are not covered. In one of the classes I see a big discrepancy between Eclipse and Salesforce online UI,  a lot of the lines that appear as not covered correspond to open and close curly brackets, but the code inside the block is covered. That leads me to believe that there is something not right with the results for individual classes in the Salesforce online UI.

 

You can give it a try with the PaymentBatcher.

 

Regards,

Fernando

Andy Freeston_LarterAndy Freeston_Larter

Nice find. I didn't notice the percentage value was a link.

 

You are correct. The line coverage is badly broken. I have red lines on empty lines, comments, and multi-line statements (where the first line of the statement is blue).

 

I will raise a case with partner support.

adreameradreamer

Thanks Andy.

 

Please let us know when you know more.

 

Regards,

Fernando

admintrmpadmintrmp

Hi,

 

I would just like to point out that Salesforce are aware of the issue. The bug number is GUS Bug # W-972046.

 

This has been an ongoing thing for the past couple of weeks and it seems that Salesforce are taking their sweet time in fixing the issue.

 

We are close to losing customers because our package cannot be uploaded due to insufficient test coverage when our coverage should easily be over 75%.

 

I'd advise everyone to push Salesforce as hard as they can to get this fixed in what should be a timely manner.

Chris JohnChris John

This appears to be resolved for me, is anybody still experiencing this issue? If so, it may be worth attempting to clear your test results as follows:

 

1. Setup > Develop > Apex Test Execution

2. View Test History

3. Clear Test Results

This was selected as the best answer
Andy Freeston_LarterAndy Freeston_Larter

It does look like the code has been improved. The per-class coverage results are now within a few percentage points of the results in Eclipse. I tried the test history reset before running the tests so I don't know if the reset had any effect.

 

The overall Code Coverage Total still looks suspiciously low. I am seeing 57% even though I only have one file at 0% and most files are between 80% and 100%. I would expect the total coverage to be between 68% and 75%. (Not that the total is critical anyway, however it is useful.)

 

Thanks for the fix Salesforce.

admintrmpadmintrmp

This works! Brilliant! Thanks for the work-around. :o)

adreameradreamer

Yes, it worked for me too.

 

Thanks for your input.

 

Regards,

Fernando