[SalesForce] Package test coverage way lower than actual

So pretty much what topic says. While trying to upload a package I get the following error:

Package upload error

However, when I check test coverage anywhere else, it shows me 77%.

Developer console:

Dev console test coverage

Setup –> Develop –> Apex Classes:

develop apex classes test coverage

And Sublime Text with MavensMate:

MavensMate test coverage

I've seen this question as well, but the problem is that I did include all classes into my package, so all test classes are in this package as well.

Also, while I was testing I raised overall coverage by about 10%(from 50% to 60% I think), then added that class into the package, but package coverage only went up by about 2%. And going from 60% to 77% gave me about 4-5% of test coverage according to the package uploader.

Am I missing something? As I mentioned previously, all classes and triggers are in the package. Or is it just some bug that I should report to Salesforce?

Best Answer

Found what was wrong with my coverage. There were no test classes written for a part of the project, so those classes never got called in any test class which lead to them being omitted from the list of classes covered and therefore them not being counted towards Overall coverage.

However, while uploading a package, after tests were run some classes didn't have any coverage at all which lead to Overall coverage being so low.

After writing a few more test classes(for the classes that were not tested), I got the coverage above 75%.

So if there are no test classes testing some class A, then this class A will neither show up in Overall Code Coverage class list, neither count towards it.

Related Topic