Apex Code Coverage: Test classes are included with 0% in overall code coverage calculation

It sounds like you may have a specific problem related to mocking; however, for those experiencing the general problem stated in the question title, "Test classes are included with 0% in overall code coverage calculation", there is another cause for this issue. As @Bujji stated in his answer, it does occur (as of Spring 15) that changing a class from a non-test class to a test class can leave coverage data behind in the org that does not appear to be cleaned up by running all tests or by clearing all test data. I have just experience this issue; in a code base that I inherited, a test utility (factory) class was not marked @isTest, and so was generating coverage - incomplete coverage, in fact. I marked it @isTest, but the class didn't get removed from coverage reporting - it just dropped to 0%, lowering my overall coverage.

Instead of deleting and re-creating the class, you can clean up the old coverage data. The documentation for this known issue (resolved in Spring 15) describes a method for clearing old coverage data which resolves this issue:

1) [experience issue]

2) In the Developer console run this Tooling API query

SELECT Id, ApexClassOrTriggerId, ApexClassOrTrigger.Name,
       NumLinesCovered, NumLinesUncovered 
  FROM ApexCodeCoverageAggregate 

3) Select all results and hit delete

4) Run all tests

If you haven't seen it before, the Query tab of the Developer console has a little "use tooling api" checkbox you'll need to check.


I'm guessing you'd want to move the FooMock definition to its own .class file. Keep only @isTest declared methods/classes in your test class file.

Or, perhaps that method needs to be declared static or global?


I finally managed to setup a new DevOrg with the class and test posted in the question.

Screenshot from the DevConsole:

DevConsole Code Coverage

Screenshot from the class overview:

Classes: code coverage

Screenshot from the upload as managed package:

Managed upload result

So, the described problem does not seem to have any real world impact.