function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JonReevesJonReeves 

100% Coverage not enough?

Just got through my first testMethod with 100% Code Coverage. However when I try and deloy it tells me:

"Average test coverage across all Apex Classes and Triggers is 66%, at least 75% test coverage is required."

 

Anyone stumble across this before?

 

cheers,

Jon

Best Answer chosen by Admin (Salesforce Developers) 
JonReevesJonReeves

so think I've worked arround the issue...

 

because I renamed the class (which had no testMethod) from queryDocument to knowledgeLearningCenterArticleHandler, then added a testMethod. I was commiting the newly named Class to Production where the old Class had 0% coverage and was causing an issue.

 

I created another class with the old name, and emptied it out completely, commited the empty old class and the 100% valid new Class and I was able to deploy. However I now have an empty Class that I can't delete. If I remove it in the Sandbox, I've no way to deploy that change to production.

 

For now it'll do. I don't think I'll be renaming/deleting class in SF again.

 

Thanks for your help.

All Answers

Starz26Starz26

It is averaging the total coverage across all of your code. Check the classes and triggers section of your org and you will see what coverage you have.

JonReevesJonReeves

So it not referring to 'just' the code I'm trying to deploy, but other code we've already deployed into production?

 

Because I'm only commiting 1 Class, and in testing that class shows 100% coverage, but after trying to deploy that 1 Class it says I only have 66% coverage.

 

Is it OK that the test is in the Class, and not separate. Or should I separate them, deploy the test, then deploy the class?

 

 

In Sandbox:

 

 

 

When I try and Deploy:

note.. please excuse my mispelling in the screenshot.

Starz26Starz26

It is OK that the test is in the class.

 

And yes, it is telling you that you only Hav 66% test coverage across all classes and triggers. Note that it says 6 test run....It runs all tests on deployment.

 

 

UVUV

You need to first improve the code coverage of your production org.. Write new test classes for the classes in production or just copy/paste the code in the Sandbox and then improve the coverage.Once you have good code coverage for the classes in prod, deploy them(only test classes)...Next step would be to deploy your newly created class having 100% code coverage.

JonReevesJonReeves

This is the part that is confusing, as this is our first class. The only one that is deloyed prior to this, is the same class (with no tests) that was renamed (to this new class), but it deployed during our trial (hence didn't require a testMethod).

 

I'll do some digging, as I think I understand the problem is elsewhere now. Cheers for your advice. I'll see if I can track down the misc class thats causing the problem.

JonReevesJonReeves

so think I've worked arround the issue...

 

because I renamed the class (which had no testMethod) from queryDocument to knowledgeLearningCenterArticleHandler, then added a testMethod. I was commiting the newly named Class to Production where the old Class had 0% coverage and was causing an issue.

 

I created another class with the old name, and emptied it out completely, commited the empty old class and the 100% valid new Class and I was able to deploy. However I now have an empty Class that I can't delete. If I remove it in the Sandbox, I've no way to deploy that change to production.

 

For now it'll do. I don't think I'll be renaming/deleting class in SF again.

 

Thanks for your help.

This was selected as the best answer