function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MukulMukul 

Test Case for a Constructor

Hi all,

 

Can anyone help me out in writing a unit test for constructor method? I am very new to writing test methods. Please help!!

 

Here is the snippet of the controller constructor code:

 

// Constructor Method public newScoreRuleController () { // Give me blank lines of my Object ScoringRule = new List<ScoringRule__c>(); for (integer i = 0; i < 5; i++) { ScoringRule.add( new ScoringRule__c() ); } }

 

 Thanks in advance!

Regards

Mukul

 

Best Answer chosen by Admin (Salesforce Developers) 
David VPDavid VP

Something like (untested) :

 

 

static testMethod void testConstructor() { newScoreRuleController scc = new newScoreRuleController(); //checking if we have 5 objects in the List System.assertEquals(scc.getScoringRule().size(), 5); }

 

 

 David

 

All Answers

mattdarnoldmattdarnold
How do you access the ScoringRule? Is it returned as part of a get method or is it public?
MukulMukul

Hi Mattdarnold,

 

Thanks for replying.

 

This is how i access ScoringRUle:

 

public List<ScoringRule__c> ScoringRule { get; private set;}

 

 

Regards

Mukul

 

David VPDavid VP

Something like (untested) :

 

 

static testMethod void testConstructor() { newScoreRuleController scc = new newScoreRuleController(); //checking if we have 5 objects in the List System.assertEquals(scc.getScoringRule().size(), 5); }

 

 

 David

 

This was selected as the best answer
MukulMukul

Thanks! That worked!

 

Regards

Mukul