5

I wrote my first test class and I am not sure if I am reading the coverage correctly. On the bottom right side, the Overall Code Coverage is at 100%. When I go to my controller, the code coverage drop down states 'none'. Why is this happening?

Code Coverage None

Code Coverage 100%

In addition, when I click the drop down button, there are no options.

enter image description here

0

4 Answers 4

7

I found out what the issue was. My Sandbox APEX Test Execution Options had 'Store Only Aggregated Code Coverage' activated. This was not allowing my drop down to view all of the tests. Deactivated and it's fixed!

1
  • Glad you got it figured out! Jul 20, 2016 at 14:35
5

Whenever you experience fluky behavior in the Developer Console, it is a good idea to try switching your workspace to see if that fixes the issue.


Take a gander at Checking Code Coverage:

To view line-by-line code coverage for an Apex class, open the class. The Code Coverage menu will include one or more of the following options depending on the tests you have implemented:

  • None
  • All Tests: The percentage of code coverage from all test runs.
  • className.methodName: The percentage of code coverage from a method executed during a test run.

Lines of code that are covered by tests are blue. Lines of code that aren’t covered are red. Lines of code that don’t require coverage (for example, curly brackets, comments, and System.debug calls) are left white.

Code coverage in the Developer Console

It doesn't really explain why there is a None view, but my guess is to make normal development more tolerable. You should click on the coverage dropdown and switch to the All Tests view to see all coverage, or see which lines you're hitting from a particular testMethod by selecting it instead.

Notice that All Tests is selected in the screenshot included in the documentation.


You must run your tests to populate this data. To clear out old test runs, I normally follow the following process:

  1. Navigate to Setup > Develop > Apex Test Execution.
  2. Click the View Test History link.
  3. Click the Clear Test Data button.
  4. Go back to the Apex Test Execution page.
  5. Click the Select Tests button.
  6. Select the "all" checkbox next to Class Name, or select specific test classes to run.
  7. Click the Run button.
  8. Once these tests finish running, double check your results in the Developer Console.

You can also query the source data yourself via the REST Explorer in the Developer Workbench by hitting the following endpoint on a GET request:

/services/data/v37.0/tooling/query/?q=SELECT+Coverage+FROM+ApexCodeCoverage+WHERE+ApexClassOrTrigger.Name+=+'NoteAndTask_Controller'

If the data doesn't show up here, it doesn't exist. If you have run your test, it passed, and you know it should call this class, contact support. If you see results, they'll look something like:

Workbench Query Results

6
  • Thank you, for some reason my Developer Console is not even pulling up the colored lines. I have read this is a bug within Salesforce but editing/saving/refreshing the class is not working. I have followed the steps you provided but still no avail. Overall Test Coverage is 100% but the drop down has no content.
    – Olivia
    Jul 18, 2016 at 21:49
  • Always try changing workspace if something weird is happening in the Developer Console. Maybe try that and then re-run the test. @Olivia
    – Adrian Larson
    Jul 18, 2016 at 22:01
  • Also, check out the workbench just to see if the data is there. I added how to do that as well to my post. @Olivia
    – Adrian Larson
    Jul 18, 2016 at 22:08
  • 3
    I found out what the issue was. My Sandbox APEX Test Execution Options had 'Store Only Aggregated Code Coverage' activated. This was not allowing my drop down to view all of the tests. It's fixed! Thank you for brainstorming with me :)
    – Olivia
    Jul 18, 2016 at 22:29
  • 1
    Just a little bit of potential insight into the none option for the code coverage dropdown. In addition to making development in the dev console more palatable, this may be an example of what's called an 'empty state' in UI/UX design. Basically, it's positive feedback that there is nothing to display (though it's typically accompanied by instructions to get out of the empty state). It's supposed to be more effective at guiding users (compared to disabling the dropdown or displaying nothing in the dropdown).
    – Derek F
    Jul 19, 2016 at 0:57
1

I get this "error" a lot as I write my code in Sublime and then see covered lines in the dev console. I say "error" because it's not really an error more so a quirk. If you make an edit to the class or the test class that code coverage goes away and displays 0%.

To get it back I run the test class in the dev console after I've made an edit and then jumping back to the controller tab the code coverage returns and shows the new value.

I suspect you did an edit after running the test so run it again and it should come back!

1
  • I have tried that and no success. My developer console isn't even showing up red or blue highlights. I found a lot of other people were having this issue but none of the feedback given to them has worked for me. I have refreshed, closed out, edited, saved, everything and nothing is kicking it into gear.
    – Olivia
    Jul 18, 2016 at 21:47
0

Olivia,

You need to click on the dropdown where it says "Code Coverage: None".

You must log in to answer this question.

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