1

I have many unit test methods (30+) in a test class that cover my class well - setting up data, setting the page and controller, calling methods and setting properties, doing asserts. But when I look at my coverage in the Dev Console, many methods and lines still show as red with a total of 43% coverage.

Another issue is that the Dev Console only lists 10 test methods from the coverage dropdown when I have a class open. I have over 30 test methods for that class.

When I run the tests for this class in the Eclipse IDE, it shows 86% vs 43% in the Dev Console.

The odd thing is if I take a test method that should have shown coverage correctly and move it to another test class, then lines now show as being covered and my coverage % went up.

What gives?

2

Look at the following screen shot:

More than 30 methods in test class

You can see 30+ test methods. Developer console only shows methods which have any role in coverage of selected main class. If a test method which does not reference main class it will not be shown in list of test methods for that class.

There is no limit for number of test methods in a test class.

| improve this answer | |
  • 2
    If you care to be technical, there is a limit-- no class can exceed a million characters. So, the answer is really "however many tests you can fit in a million characters." – sfdcfox Aug 16 '14 at 14:56
  • Why would a test method in one test class not show coverage - but when added to another test class then show coverage? – Jojo Aug 16 '14 at 14:56
  • Example, for A.cls there is ATest.cls with 30 test methods. For a specific method, the relevant lines in A.cls show no coverage. BTest.cls is created with just that test method - and now the relevant lines show coverage. Same code, same test methods, just run from different test classes. – Jojo Aug 16 '14 at 15:00
  • Maybe it's related to version? These classes are v28. – Jojo Aug 16 '14 at 15:03
  • @jojo Make your class version at least 30.0, if there is no compatibility issue. Latest version has advantages. Also, writing test methods in main class is not a good practice. You should write a separate test class. In latest version you can not write test methods in a class which does not has @ isTest annotation. – Ashwani Aug 17 '14 at 6:20

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.