3

I have been using Force.com IDE to work on VisualForce pages and classes directly in a live development environment. I was unaware of the requirement that 75% of your code had to be covered by tests. Suddenly today, when I wanted to change one line of code in one of my classes, the file fails to save with this error message:

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

So I wrote some test methods to get the coverage for the class I am working on to 78%, but it still won't save. Catch 22?

What shall I do?

Update:

I am trying to improve my code coverage by adding tests in my sandbox org and then deploying that to the development org via change sets. For example:

  • I take a class that has no coverage
  • write some test methods that covers the code more than 75%
  • make a new change set and add the class
  • upload the change set to my development org
  • when I try to deploy the change set in my dev org, the deployment fails with

Deploy Error | Average test coverage across all Apex Classes and Triggers is 15%, at least 75% test coverage is required.

Also trying to deploy one class via Force.com IDE fails with the same method. Does this mean that I can't fix and deploy class by class?

  • You put your test methods in a separate test class, right? And is all of this in a sandbox/dev org? – Mike Chale Jun 20 '13 at 14:19
7

If you are doing development in your live production environment, I suggest changing to a sandbox org first. Create a sandbox, configure the IDE to connect to the sandbox, and make all your code changes there. You can run tests there to see how good your coverage is. Once you are at 75% for the org (bare minimum), deploy your new code to production and it should succeed.

Developing in production is not impossible, but it's definitely not best practice. I learned the hard way that it's not worth it in the long run, even if it seems like it's saving you time right now.

  • Thanks, Jeremy. Is there a way that I can improve coverage and deploy classes one at a time? See the update in my question. – JannieT Jun 21 '13 at 13:07
  • When you deploy a change set, all of the test methods in the org run right then. If it's not covered at least 75%, the deployment fails. It doesn't matter if coverage is better than it used to be, if it's still under 75% for the org as a whole. You'll need to wait to deploy until your whole sandbox is above 75%, then deploy everything at once. – Jeremy Nottingham Jun 21 '13 at 13:35
  • What will happen if I delete all the apex code from my sandbox org except the one class I want to update and then upload a change set? – JannieT Jun 21 '13 at 15:11
  • What's important is what the org coverage will be in your production instance at the moment that you deploy your change set. Changing your sandbox environment will not affect that, only the contents of the change set will. – Jeremy Nottingham Jun 21 '13 at 15:20
4

wApex is complaining about test coverage of your org and not your class. You need to find the overall test coverage your org has.

To find this:

Go to setup --> apexclasses --> hit run test button( warning: this would lock th e org and may cause some deploys to fail)

Alternatively you can also click on

Estimate your orgs code coverage above the classes list view, but the catch is that the results this link shows is based on the last time the run all test was calculated. This means your orgs coverage might have dropped / increased due to a package install or new code push which will make a false number that may make you assume you are still at 75% mark.

So best option is to click on the run all test and make sure the coverage is above 75%, if not welcome to world of pain , revisit all your classes that have less than 75% atleast and rewrite test classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.