8

The Apex coverage results for unit tests in the Force.com IDE and the developer console are very different. I just ran 2 tests in both and got:

test 1
IDE: 75 lines not tests, 68% covered
Developer Console: 52% covered

test 2
IDE: 57 lines not tests, 76% covered
Developer Console: 57% covered

I'm wondering if this is because the developer console is counting blank lines differently (they show up highlighted in red). The IDE seems to have the correct number and I'm also wondering how to get the correct number from the developer console, which is much faster than the IDE for running my tests.

  • See salesforce.stackexchange.com/questions/3689/faster-unit-tests for some good ideas. Dev Console and Apex Test Runner are known to be unreliable. If I need to rely on running tests from UI I make sure to clean old test results (it seems some kind of caching/stalling is at play). – eyescream Nov 7 '12 at 23:03
  • Thanks, that's my question also :) They generate the same log, but seem to calculate the percentages differently and would like to find out what that difference is. – paul Nov 7 '12 at 23:36
  • I've generally found the only reliable measure of test coverage is the one generated when building a package. All others come up differently. – James Davies Nov 8 '12 at 1:26
  • Because life is more fun when things behave differently for unknown reasons? Why else would we be doing Enterprise Dev :) – Ralph Callaway Nov 8 '12 at 3:47
5

This is a known problem and MVPs like Jeff and Wes have good posts about the same. Here are links for reference:

http://th3silverlining.com/2011/11/30/salesforce-different-percentage-code-coverage-in-different-environments/

http://blog.jeffdouglas.com/2011/11/22/apex-test-coverage-does-not-match/

I think one way is to clear the Test execution history from "Setup > Develop > Apex test execution", and try again. Running all tests might help getting more accurate coverage after cleaning the stale results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.