You need to sign in to do that
Don't have an account?
gv007
Test Coverage for StandardSetController Class .How i can coverage it in my code
Hi We have an tricky situation my all the apex class are covered more then 85% except one class use an StandardSetController Class .Here is my sample code how i can cover the code. Somebody can help me to cover the line in test coverage.
List<Custom Object> variable1 = (List<Custom Object>)xyz.getSelected(); I am getting the p_stdSetController from my constructor here is the code ApexPages.StandardSetController xyz. List<Custom Object> variable1 = (List<Custom Object>)xyz.getSelected(); this line is hitting the code coverage .
I think what you are looking for is setRecords(); on the standardsetcontroller injected into the extension.
Something like this:
public class extension { public ApexPages.StandardSetController con; Boolean success; public Extension(ApexPages.standardSetController con) { this.con = con; success = false; } public void save() { if(con.getSelected().size() > 0) { success = true; } } public static testmethod void testselected() { List<Account> accounts = new List<Account>(); for(Integer i=0;i<10;i++) { accounts.add(new Account(Name = 'TEST' + i)); } insert accounts; ApexPages.StandardSetController con = new ApexPages.StandardSetController(accounts); con.setSelected(accounts); Extension ext = new Extension(con); Test.startTest(); ext.save(); Test.stopTest(); System.assert(ext.success); } }