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
DekorDekor 

Deploying test class to production org which is currently below test coverage

So I uninstalled a package we no longer used earlier today which I assume has brought down our average test coverage.

I'm now trying to deploy an updated version of an existing class and its failing obviously due to low code coverage.  So sort this I have written a test class in our sandbox which runs fine and works with one of the existing classes in my production org.  However if I try to deploy the change set from my sandbox to production it is failing again due to code coverage.

How on earth am I meant to boost the test coverage if I cannot deploy new test classes????
varun_vatsavarun_vatsa
I think you are trying to deploy a single test class, which might not be enough to take the average test coverage by 75%. so in order to deploy you need to cover all the classes already on production and deploy those all test classes in a single go.

On production while we do any deployment "Run All Test" executes, so you need to do the same on your sandbox, to see which all classes are not covered appropriatley and then fix them one by one.
DekorDekor
Could I delete some apex classes from our production org that do not have test classes?  I'm struggling to find a way to do this. 
varun_vatsavarun_vatsa
Hi Dekor,

That could be really complicated, as in order to delete any class from production you need to delete it from Sandbox first, then in package.xml file change the status of that class to "deleted" and do the DEPLOYMENT. Again, causing Run all tests to execute and giving compile time issues if the classes you have deleted are been refrenced in other classes!! 

So I would recommend fixing the test coverage and by deleting existing classes you may break some of your existing functionality too.

 
DekorDekor
Ok, so I've written two new tests in my sandbox but when I try to deploy them to my production org it fails, due to code coverage.  Surely without additional tests I can't get the code coverage up? 
DekorDekor
Ok, after deleting a class I know longer use I have been able to import two new test classes and code is back to 75%.