You need to sign in to do that
Don't have an account?
Mubarak
Method does not exist
Test Class
@isTest
Public Class AddRowControllerTest{
Static testmethod void Addrow(){
List<Contact>con=new List<Contact>();
Contact c=new contact();
c.firstname='Test';
c.lastname='Test';
Con.add(c);
insert con;
System.AssertEquals(c.firstname,'Test');
System.AssertEquals(c.lastname,'Test');
system.test.startTest();
AddRowController arc=new AddRowController();
arc.AddRowController(con);
arc.AddRow(con);
System.test.stopTest();
}
}
Apex Class.
public class AddRowController {
Public Contact contact{get;set;}
Public list<Contact> listContact{get;set;}
Public AddRowController(){
Contact contact=new Contact();
List<Contact>listContact=new list<Contact>();
listContact.add(contact);
}
Public void AddRow(){
Contact con=new Contact();
listContact.add(con);
}
public PageReference saveContact() {
for(Integer i=0; i<listContact.size(); i++)
{
insert listContact;
}
return Page.Properties;
}
}
.In test class without 2 methods addRowController() and addRow() am getting 28%code coverage bt if i included these two methods am getting error like Method does not exist or incorrect signature.
Note:I dont have any other class with name "Test".
can anyone tell me what might be the reason for this error in test class.
Thanks
@isTest
Public Class AddRowControllerTest{
Static testmethod void Addrow(){
List<Contact>con=new List<Contact>();
Contact c=new contact();
c.firstname='Test';
c.lastname='Test';
Con.add(c);
insert con;
System.AssertEquals(c.firstname,'Test');
System.AssertEquals(c.lastname,'Test');
system.test.startTest();
AddRowController arc=new AddRowController();
arc.AddRowController(con);
arc.AddRow(con);
System.test.stopTest();
}
}
Apex Class.
public class AddRowController {
Public Contact contact{get;set;}
Public list<Contact> listContact{get;set;}
Public AddRowController(){
Contact contact=new Contact();
List<Contact>listContact=new list<Contact>();
listContact.add(contact);
}
Public void AddRow(){
Contact con=new Contact();
listContact.add(con);
}
public PageReference saveContact() {
for(Integer i=0; i<listContact.size(); i++)
{
insert listContact;
}
return Page.Properties;
}
}
.In test class without 2 methods addRowController() and addRow() am getting 28%code coverage bt if i included these two methods am getting error like Method does not exist or incorrect signature.
Note:I dont have any other class with name "Test".
can anyone tell me what might be the reason for this error in test class.
Thanks
Replace arc.AddRow(con); to arc.AddRow();
ApexPages.StandardController sc = new ApexPages.StandardController(con);
AddRowController arc=new AddRowController(sc);
arc.AddRowController();
arc.AddRow();
................................
Because you are in the methods you should not pass any values. Because in the main class there is no passing any values.
Please try this.
Thanks
You are doing two mistake in your test class .
1.AddRow is a method without parameter, however you are passing parameter to that .
arc.AddRow();
2.AddRowController is your constructor you can not call like below .
remove below line and call the save method it will work .
arc.AddRowController(con);
Let me know any issue .
In my reply I posted
arc.AddRowController(); Please remove this part and test.
Thanks
Remove - arc.AddRowController(con);
Replace arc.AddRow(con); to arc.AddRow();
Your Class should be
and test Class as :- NOTE: This code has not been tested and may contain typographical or logical errors
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks,
Amit Chaudhary