I've looked at a few questions but couldn't find the responses that worked for me. I've attached a screenshot of my classes and all of their code coverage. Any class ending in test is a test class.

Salesforce is counting my test classes as coverage. I'm at 59% according to them but 72% with non-test classes included.

I've included a test class example to see if there is something I did wrong.

public class MobileActivityControllerTest {

    static testmethod void testExistingWorkday(){
        mobileActivityController mobile = new mobileactivityController();
        mobile.geoLat = 0.0;
        mobile.geoLong = 0.0;
        mobile.owner = [select id, name from user limit 1];

        workday__c myWd = createWorkday();
        insert myWd;
        list<Activity__c> myActs = createActivities(myWd);
        insert myActs;
        mywd.Work_Date__c = date.today();
        update mywd;


    static list<activity__C> createActivities(workday__c wd)
        list<activity__c> myActs = new list<activity__c>();
        myActs.add(new Activity__c(workday__c = wd.Id, end_workday_activity__c = true));
        myActs.add(new Activity__c(workday__c = wd.Id, start_workday_activity__c = true));
        myActs.add(new Activity__c(workday__c = wd.Id, 
                                  city__c = 'madison',
                                  zip_code__c = '35344',
                                  check_in_time__c = datetime.valueOf('1954-01-01 20:03:20'),
                                 check_out_time__c = datetime.valueOf('1954-01-01 20:03:20'),
                                 GeoCode__Latitude__s = -2.0,
                                GeoCode__Longitude__s = -2.0));
        myActs.add(new Activity__c(workday__c = wd.Id));
        return myActs;

    static workday__c createWorkday()
        workday__c myWD = new workday__c();       
        myWd.Name = 'asdf';
        mywd.Work_Date__c = date.valueof('1954-01-01');
        myWd.OwnerId = UserInfo.getUserId();
        return myWd;        


Code coverage


  • It is very difficult to go through all the lines.Can you share screenshots with non coverage lines in your codes.
    – Pavan tej
    Sep 1, 2016 at 20:05
  • The above class has 0% coverage because it's a test class. It should have either 100% coverage or not be included in the calculation.
    – tjcinnamon
    Sep 1, 2016 at 20:06
  • Your 'helper' methods in your test class count against you. Only methods marked as test methods are exempt from this requirement. Sep 1, 2016 at 20:06
  • @JesseMilburn seems like a near duplicate of your question today.
    – Adrian Larson
    Sep 1, 2016 at 20:07
  • If they're static then I can't call them and therefore cannot test them
    – tjcinnamon
    Sep 1, 2016 at 20:08

2 Answers 2


This is a quirk of some developer/sandbox organizations. I ran up against it when taking the Adv Dev programming exam. When you push to production, it will adjust to exclude any methods (helper or @isTest) when you go for a production deployment.

  • 1
    Unlike @TestSetup methods, helper methods are not guaranteed to be called. Are they still excluded?
    – Adrian Larson
    Sep 1, 2016 at 21:33
  • 1
    @AdrianLarson Any code within a class marked as @isTest does not count towards the calculation. You are not required to unit test your unit test helper methods.
    – sfdcfox
    Sep 2, 2016 at 4:22
  • @sfdcfox According to this document: help.salesforce.com/apex/…. Including code other than test methods in an @isTest annotated class will cause these lines to be counted in the overall code coverage numbers? Am I missing something? Sep 2, 2016 at 13:16
  • @JesseMilburn That's actually what this answer is saying; your estimate may be inaccurate when using Run All Tests, but will be calculated correctly during deployment. In most orgs, the difference between the estimate and actual is probably +/- a few percent, but orgs with lots of HttpCalloutMock classes, etc may have a wider margin of error. Just make sure you keep your "non-isTest" classes above 75% each, and you'll be okay.
    – sfdcfox
    Sep 2, 2016 at 14:36
  • After pushing some code, all of the test classes just disappeared from the count. No clue why but they are all gone. So I don't have an answer short of, "they all just disappeared"
    – tjcinnamon
    Sep 14, 2016 at 14:03

I ran in to this issue. What could have happened is, test class was created without @isTest annotation (at this point the class has been added to the code coverage table) and @isTest was added later (but this doesn't remove the class from the table). This usually happens if you create test classes in Developer Console. Delete and recreate the class and make sure @isTest is added at the time of creation itself. Create the test classes through Force.com IDE, Mavensmate or from setup page. The test class should disappear from code coverage table.


You must log in to answer this question.

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