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
TechSteveTechSteve 

Sandbox code coverage not on production site?

Hi all, I have been developing a site in the sandbox which has unit testing code with between 70 - 92% code coverage with a calculated 78% average. I know this isn't a great job well done but it meets minimum requirements for now.

But then when I migrate it to the production environment, the live site, the validation check says it will fail to install with 0% code coverage. How can that be?

Why would it say that?

Do all classes have to exceed the 75% individually?

If any system.assert tests fail, would that cause my problem?

Has anyone got anything that will help me?

I have not got a clue as to why this is the case. Please some advice would be a god send!

 

Thanks in advance,

 

Steve

hemantgarghemantgarg

90% chances that while developing unit tests on sandbox you had all the test data in place, but in production you dont have test data. hope it make sense.

Prafull G.Prafull G.

as posted by hemantgarg, you must be using sandbox data to run your tests. You should create all test data into unit test methods itself.

Also, It is not necessary to have minimum 75% coverage individually. Triggers must meet minimum 1% code coverage and overall(average) coverage for apex code(classes and triggers) should exceed 75%.

 

If any system.assert tests fail, this will definately reduce your code coverage and test failures doesn't allow you to deploy data to production.

 

Hope this helps.

 

Regards,



TechSteveTechSteve

Thank you both,

once the system.asserts are sorted how do I get validation to clear when the test data is not accessible until it is on the site but won't go on the site till I have data in it? a little confused. Sorry.

Will it load onto the site even if it fails validation just for test data problems?

How do I add the test data in production before it loads?

Why does it not use the same data in the test unit like it does in the sandbox?

Please if you can help. This is very infuriating.

 

Thanks

Steve

Prafull G.Prafull G.

Hi Steve,

 

You can create test data in testmethods itself. Operations performed in test classes (DML operations) does not commit any data into org.

 

Below url has significant details and the way test data supposed to be created in test methods.

Please visit http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods