Many people are finding that their tests are reporting different degrees of test-coverage in different environments. There are a few things to check if you are getting inconsistent results but there’s a new bug in the wild. Before you assume you have the bug make sure that you’ve:
- ‘Run All Tests’ in each environment. This will tell you a few things viz.
- Perhaps there are tests failing that are bringing coverage in that environment down.
- There are some tests that only fail when run in the browser e.g. MIXED_DML_EXCEPTION will not rear it’s head through the IDE.
- Click the ‘Compile all classes’ link above the Setup > Develop > Apex Classes view. I’m not sure when this lil’ bugger first appeared but it’s darn useful. Essentially it makes sure that all the dependencies in your code are fulfilled e.g. if page A uses controller B that in turn refers to utility class C it’ll make sure each of those pieces exist and work (as far as compilation goes at least).
- Double-check your test classes to make sure they’re not data dependent. If they are and you have different types/amounts of data in your respective environments it’s 100% feasible that the test coverage will be different.
Now if you’ve checked all of the above you might have been afflicted by a new bug which, for some reason, counts braces, whitespace (and more!) as being uncovered by your tests. This is preposterous of course and to fix it simply remove all test history from the deranged environment. Re-running the test and/or deploying them should now be back to normal!
The MIXED_DML_EXCEPTION thing in the IDE is being fixed. That said, you should be running your tests in the Apex Test Execution page now 🙂
Data dependent tests will be a thing of the past in #spring12 so long as you don’t disable the new data silo in your tests with @IsTest(SeeAllData=true). Otherwise, SOQL queries and suchlike will only see data created in the test.
Dude that’s some pretty exciting news! Thanks for the update.
Over 3 years later… still not fixed. I just confirmed with Salesforce support that DML will show when testing in browser, but not in Force.com IDE.