Authored by Zishan Razzaq

Thursday, August 23, 2012

How to check code coverage for a NON Developer on Salesforce.com

Hi everyone:
Scenario:
As a Project Manager/Program Coordinator or BA of a company, you do not have the skill set of checking if code meets coverage for salesforce.com best practices or the company's policy on code coverage. Sometimes you must rely on the developer's word on test coverage for Apex Trigger/Controller or Visualforce page.
But it is your responsibility to make sure that test coverage is met, no matter what.

Solution:
Now Salesforce best practices on test classes is always 100% or 95%.
Now salesforce passing grade is 75% but it reccommends 100% or 95% and above.
How does one check to make sure its is meeting your standards or even salesforce standards.

  1. When a developer is showing you a trigger/Apex Controller/VisualForce Page and how it is working, as a Non Developer always asked May I see the test class for this trigger or Apex Controller.
  2. Tips for Non Developer:
    1. If the developer wrote a trigger then the Test Controller must be in a separate class.
    2. The test controller can be in a global class that houses all trigger test scenarios all in one.
    3. If the developer wrote a Apex Controller with a Visual force page then the test controller can be in the same class as the Apex Controller.
    4. The test controller can be in a global class or a separate class as well.
  3. I will show you a couple of scenarios here:
    1. I wrote a Apex Controller that does something and then within the same class i wrote the test scenario. As a Non Developer ask the following:
      1. Is this a Apex Controller?
        1. If yes, please show me the Apex Controller.
        2. Once the developer goes to that screen (not in edit mode) Look for "Run test" button, this means the test controller was written inside the same class.
        3.   
        4. Once you see that ask the developer to click on that button to show you test coverage.
        5. Once the developer does, it will bring up all triggers/controllers everything in your instance but your main concern is the apex controller that he/she is showing you at that time. Look for the name of the Apex Controller.
        6. In this case it is "AccountProcessor"
        7. You can see by the screenshot it is at 100%.
9. Now lets say it was at 0% or 60% when the developer ran it, how can you as a  non developer check what is the developer lacking in his test coverage.
10. I made changes and now I will show you the test class ran and it is at 0% meaning nothing is covered by the controller. So maybe the developer did not do a test class or he/she is not done with test class, and from my previous company that is not the Definition of Done (DOD), it would be back to the drawing board for this person.
11. You as the Non Developer should ask the developer to click on the 0 link as you see in the screenshot:
12. Once he/she clicks on it then it pops open a box and tells you as the developer or non developer in colors red being not covered and blue being covered.
Since my Controller class and test coverage was in the same class, it shows from the main class where the developer showing the functionality of what needs to be presented and in red it shows what have i missed.

This is one of many ways to test out for NON coders or developers of how to ask for test coverage.
Just a few tips:
Test coverage within a Apex Controller always starts with:
"public static testmethod void testControllerName(){" in the above example it is "
public static testmethod void testProcessAccount(){"
 
or if it is in a separate class that it 
would start with the following:

"@isTest(SeeAllData=true)
publicclass TestDataAccessClass {

    // This test accesses an existing account.  
    
    // It also creates and accesses a new test account. 
    
    static testmethod void myTestMethod1() {"
Always check for Run Test on classes. They only appear on 
Apex Classes not on Triggers.
For Triggers the developer must write a 
separate class for test coverage.
 
Thank you

I hope this helped.

Watch Me Fight 
Join My Facebook on Cage Assassin Fight Gear  Like my fan page Cage Assassin Fight Gear  





No comments:

Post a Comment