You need to sign in to do that
Don't have an account?
Manid
test class for standardsetcontroller
public class MassDelete { public list<account> accs {get;set;} public MassDelete(apexpages.StandardSetController cont){ string[] fields=new string[]{'name','industry','rating','phone'}; cont.addfields(fields); accs=new list<account>(); accs=(list<account>)cont.getselected(); } public pagereference deletes(){ delete accs; pagereference p=new pagereference('/search/UndeletePage'); return p; } }my test class:
@isTest public class MassDeleteTest { testmethod static void testme(){ list<account> accs=new list<account>(); account a=new account(name='Test name'); insert a; account a2=new account(name='Acme pro'); insert a2; accs.add(a); accs.add(a2); test.startTest(); pagereference pref=page.massDeleteAcc; test.setCurrentPage(pref); apexpages.standardsetcontroller std=new apexpages.StandardSetController(accs); std.setselected(accs); MassDelete obj=new Massdelete(std); test.stopTest(); } }i didn't get full coverage why?
@isTest
public class MassDeleteTest {
testmethod static void testme(){
list<account> accs=new list<account>();
account a=new account(name='Test name');
insert a;
account a2=new account(name='Acme pro');
insert a2;
accs.add(a);
accs.add(a2);
test.startTest();
pagereference pref=page.massDeleteAcc;
test.setCurrentPage(pref);
apexpages.standardsetcontroller std=new apexpages.StandardSetController(accs);
std.setselected(accs);
MassDelete obj=new Massdelete(std);
obj.deletes();
test.stopTest();
}
}
Please check below post for sample test classes
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Please try below code
Please excute the above code and let us know if you will get any error and you will not get 100% code coverage please post which lines are not covred
Try to updated your code like below Test class should be like below
Let us know if this will help you