-1

I need help creating a test class for the following apex class in order to get code coverage. Any thoughts or examples that could help me figure this out would be greatly appreciated. A previous developer created a bunch of classes and deployed them to production without unit testing any of them and now our Salesforce org is feeling this effect because we have dropped below the standard 75% code coverage limit. I'm cleaning up this by writing test classes to perform unit testing on these classes.

public class interviewEvaluationExtension {

    private final Admissions_Interview_Evaluation__c eval;

    // The extension constructor initializes the private member
    // variable acct by using the getRecord method from the standard
    // controller.
    public interviewEvaluationExtension(ApexPages.StandardController stdController) {
        this.eval = (Admissions_Interview_Evaluation__c)stdController.getRecord();

        //could be improved by not hard coding field ID
        List<Opportunity> opp = [select Id, AccountID, EMPLID__c, ACAD_PLAN__c, PLAN_DESCR__c, ADMIT_TERM_DESCR__c
               from Opportunity 
               where id = :ApexPages.currentPage().getParameters().get('CF00N80000005VcoB_lkid')];

        if(opp.size() > 0){
            eval.Interviewee_Application__r = opp[0];
        }

        List<Account> acc = [SELECT Id, FirstName, LastName
                            FROM Account
                            WHERE Id = :eval.Interviewee_Application__r.AccountID];
        if(acc.size() > 0){
            eval.Interviewee_Application__r.Account = acc[0];
        }

        eval.Name = eval.Interviewee_Application__r.EMPLID__c 
                    + ' - ' 
                    + eval.Interviewee_Application__r.Account.FirstName
                    + ' '
                    + eval.Interviewee_Application__r.Account.LastName;

    }
}
1
  • 4
    What have you done so far?
    – dphil
    Feb 13, 2015 at 16:02

1 Answer 1

1

Generally, you should make some sort of attempt before you ask for help. Here are a few good resources to get you started. Because your constructor is doing all the work, you can "smoke test" to get good coverage by simply instantiating the class, but you will better protect functionality by writing "unit tests" that actually cover cyclomatic complexity and assert on results.

So smoke tests just run everything and see if it throws an exception, whereas unit tests run code "units" and ensure they perform as expected. Note that security scanners will pick up if you have no asserts in your tests.

1
  • Thank you for your help, I was able to get my unit test to run.
    – Vincent
    Feb 14, 2015 at 6:02

You must log in to answer this question.

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