Can any one let me know why the test class code coverage gets varied.

1)When I test individual testclass (controller) in the sandbox the code coverage shows as 35% only .

2)when I Run all the test classes in the sandbox ,then the testclass(controller) shows as 48%.why is the variation occurs.

Any suggestion please.

  • A test class and a controller are not the same thing. The apex test class is code that should be testing some other code, such as a controller. Can you clarify your question? Apr 16, 2015 at 12:23
  • @ Jeremy Nottingham:Controller is the name of the test class.
    – nikkey
    Apr 16, 2015 at 12:26

2 Answers 2


One or more methods of the controller are being called (maybe indirectly) by other test classes, so you get more coverage.

Using the Developer Console, you can discover which lines in the class were covered by which test classes.

  • :I do have doubt but when we move the individual test class into production at that time it gets varied and the overall organization code coverage gets reduced less than 75% .Then how to improve the overall organization code coverage.Any help very much appreciated.
    – nikkey
    Apr 16, 2015 at 12:28
  • It is also ppssible that you are handling an error that is causing other code to not be executed to drop. Are you deploying anything that is enteractig with other code? Also if you run the test through mavens mate or eclipse the log will come back in one file so you can check for exceptions more easily.
    – Chris
    Apr 17, 2015 at 3:07

When you perform run all tests, then test methods from other test classes are covering your test class for controller and hence you get more coverage.

And for deployment, you need atleast 75% overall code coverage.for that check for all the classes in your org. Check if each class has test coverage of at least 75%. So it will cause overall coverage to increase.

You must log in to answer this question.

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