I have created a Test Data Factory helper class to create Test Data for testing my apex code like suggested in the documentation here: https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_testing_utility_classes.htm

The TestDataFactory methods that don't have any parameters like so:

public testmethod static void CreateProducts()

can be marked with the testmethod keyword and don't count against code coverage. However, if the method has parameters like they have in the documentation example and like below:

public static void CreateBusinesses(Integer NumberOfBusinessesToCreate)

you cannot mark it with the testMethod keyword or @isTest attribute because you get the error "Test methods must have no arguments". Keep in mind, the TestDataFactory class that holds all these methods is decorated with the @isTest attribute as well.

The problem is, my TestDataFactory class is quite large and has many methods, and any of the methods that aren't marked as test methods are being counted as uncovered towards my code coverage (the developer console shows uncovered lines). The methods that are marked as testmethods are being counted as covered.

Also, some people have mentioned it might be an issue with the developer console and maybe it isn't actually counting it, but it is counting it because at first I didn't have any of the methods in the TestDataFactory class marked as testmethod and my code coverage was 65%; then I marked the methods that had no parameters with testmethod and code coverage on the org increased to 70%.

Anyone have any idea how to resolve this issue so that TestDataFactory methods are not counted against code coverage?


1 Answer 1


I've heard many people asking similar questions with the same issue.

This is a bug with the displayed code coverage but will not be factored into minimum coverage deployment calculations.

This is most likely caused by initially creating/saving your test factory class without the @isTest prefix. If you follow these instructions you can remove the incorrect data. Then when you rerun tests it should not reappear.

  • Can you link a source for this information, please?
    – mkorman
    Mar 1, 2016 at 13:47
  • Sure. I also added instructions on how to remove the bad data. Let me know if you have any problems.
    – Venko
    Mar 1, 2016 at 13:49
  • @Venko I followed all the steps in section 1 of your link to re-run all tests. However, I previously tried to perform the remove bad data section where I run the query and delete all rows, but I get the following error when running the query: sObject type 'ApexCodeCoverageAggregate' is not supported. Mar 1, 2016 at 13:53
  • 1
    @reverence12389 Did you check "Tooling API"?
    – Venko
    Mar 1, 2016 at 13:54
  • @Venko Checking "Tooling API" fixed the error. I was able to delete all the rows and once I deleted all the rows the coverage issue for my TestDataFactory was fixed. Thank you! Mar 1, 2016 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .