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
PaddybPaddyb 

Code Coverage for Deployment

I am trying to deploy from my Sandbox to Production. I 'Ran All Tests' and the code coverage is 75% but when I try to deply after running all tests - I get an error in production telling me that I dont have > 75% code coverage?

Any ideas?

PaddybPaddyb

Also I cant deploy a test class to increase the coverage - it gives me an error that the coverage is not high enough!

soofsoof

Run all tests in Production, and see what you get.  The coverage might've dropped in Production for some reason.  If all looks good in production, validate your deployment plan and you'll be able to see the classes that have low coverage.

 

Thanks.

PaddybPaddyb

Thats the problems, the code coderage is lower in production (72%). But I cant deploy test clases to increase this because of the low code coverage

soofsoof

So it is a perpetual ordeal... you're in for a long, long weekend, buddy!

 

Here's how I would've fixed this (perhaps you're already going through this painful procedure):

1) Run All Tests on production.

2) Pick classes whose coverage is way too low.

3) Write test code in Sandbox, and try to deploy.

4) Upon each failure, review which classes still lack coverage, and work on them.

 

While you write test code, make sure that you create data for your tests instead of relying on real data in the org.  Since the data in sandbox and prod can be different, tests passing in sandbox may fail in prod.

 

Now, I have a VERY, VERY dirty work-around that comes in handy when you're fighting against time.  Create fake classes that have no 'actual functionality', but just jack up coverage.  For instance:

public class TrashClass {
	public TrashClass() {
		String trashString = 'This is a trash string... just increasing coverage';
		trashString = 'This is a trash string... just increasing coverage';
		trashString = 'This is a trash string... just increasing coverage';
		trashString = 'This is a trash string... just increasing coverage';
		trashString = 'This is a trash string... just increasing coverage';
		// Keep going on and on and on.......
	}
	public static testmethod void testTrashClass() {
		new TrashClass();
	}
}

 

This will just give you the ability to be able to start working on the Production instance to increase test coverage.  If you decide to go ahead w/ this, do make sure that you eventually write test code for all your 'real' classes, and delete this fake class.

 

Hope this helps.

 

Thanks.