Test Classes for Standard/StandardSet Controllers

Apex Dec 18, 2014

Following are basic steps we wonder while writing test classes, please find each code statement explained using comments

Order is Very important here first you need to create visualforce page then controller/extension

// setting visualforce page
PageReference pageRef = Page.<<Vf_page_name>>;      
// putting parameters in Apex Class ~ query stirng
ApexPages.currentPage().getParameters().put('qString', '<param_value>');

// Initialising Standard Controller Extension
ApexPages.StandardController sc = new ApexPages.StandardController(<<dummy_object>>);
// Initialising controller
apex_class_example t = news apex_class_example(sc);
// using getter & setters, lets say 'acc' is an string variable
t.acc = 'Dummy text'; // assign getter & setter correspondingly to DataTypes
t.call_methods(); // I included dummy method here please include yours

// Initialising StandardSetController Extension
ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, OwnerId FROM Case LIMIT 2]));
setCon.setSelected([SELECT Id, OwnerId FROM Case LIMIT 2]); // this method gives selected records
apex_class_example t = news apex_class_example(setCon);
// I included dummy method here you can add your extension methods 

Phanindra Mangipudi

Salesforce, Lightning Web Componets, Node.Js, Angular 2+, Bootstrap