salesforceapex-codevisualforcetest-class

How to create code coverage for my Apex Class


Here is the class I managed to create, not sure where to start with code coverage as this is my first apex class, or doing anything with salesforce.

Can someone point me in the right direction. Thanks!

public with sharing class VelocifyAcctStatsController 
{
public List<Account> acctstats {get;set;}
    public VelocifyAcctStatsController()    
{
    acctstats = [select MVA_Type__c, MVA_Name__c, MVA_Is_VIP__c, MVA_Is_Brand_TM__c, MVA_Classification__c, MVA_Classification_Priority__c, Assets_Owned__c, Portfolio_Overview__c, Active_Opportunities__c, X3x3_Research_One__c, X3x3_Research_Two__c, X3x3_Research_Three__c from account WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];
}
}

Solution

  • This should help you get started:

    @isTest
    public class VelocifyAcctStatsControllerTest {
    
        @isTest
        public static void test(){
            Account a = new Account(Name = 'Test acct' );
            insert a;
    
            ApexPages.currentPage().getParameters().put('Id', a.Id);
    
            VelocifyAcctStatsController v = new VelocifyAcctStatsController();
    
            System.assertEquals(v.acctstats.size(), 1);
        }
    }