You need to sign in to do that
Don't have an account?
constructor not defined in test method
Hi every one
i have one test class ,i am getting error while run the testcase " constructor not defined in test method"
i am not getting the exact senario that cause this error before that i deploy many class same like this.
My test class look like
@isTest
private class FFPageTestCase {
static testMethod void myUnitTest() {
FF__c FF;
List<Opportunity> listOpp;
String Id;
String result;
string oppmsg ;
oppmsg = 'Error';
string oppmsg2 ;
oppmsg2 = 'Success';
Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'Ticketing';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.Override_Itinerary_Builder__c = true;
opp.Complete_Itinerary_Information__c ='test';
opp.Approved__c ='Test1';
opp.AmMessage__c ='ttttt';
insert opp;
FF = new FF__c();
FF.Account_Number__c ='1234456';
FF.Account_Type__c = 'ANA';
FF.DOB__c = system.today();
FF.Opportunity__c = opp.Id;
FF.Last_Name__c = 'Dutt';
FF.Miles__c = 1.2;
FF.Password__c= 'asd';
FF.Mileage_Cost__c = 0.0210;
insert FF;
ApexPages.StandardController sc = new ApexPages.StandardController(FF);
FFPage sc1 = new FFPage(sc);
sc1.Save();
update FF;
delete FF;
}
}
My class look like
public class FFPage {
FF__c FF;
public List<Opportunity> listOpp;
public String Id {get; set;}
private String result;
public FFPage(ApexPages.StandardController stdController)
{
FF = (FF__c)stdController.getRecord();
Id = FF.Opportunity__c;
}
public void Save()
{
try
{
if(FF.Id == null)
{
insert FF;
string oppmsg = 'Error';
//Opportunity oppmsg = [SELECT id,AmMessage__c FROM Opportunity WHERE Id = :FF.Opportunity__c];
if(oppmsg != 'Success')
{
delete FF;
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.WARNING, 'Test'));
}
}
else
{
update FF;
string oppmsg2 = 'Success';
//Opportunity oppmsg = [SELECT id,AmMessage__c FROM Opportunity WHERE Id = :FF.Opportunity__c];
if(oppmsg2 != 'Success')
{
delete FF;
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Sucess'));
}
}
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
}
public PageReference SaveAndNew()
{
PageReference pr = new PageReference('/' + Id);
pr.setRedirect(true);
return pr;
}
}
please help me .
Thanks
i tried these things also but not worked.
1.ApexPages.StandardController sc = new ApexPages.StandardController(opp);
2.ApexPages.StandardController sc = new ApexPages.StandardController(new opportunity());
You need to update your test class for this. There are below two lines which needs to update
ApexPages.StandardController sc = new ApexPages.StandardController(FF);
FFPage sc1 = new FFPage(sc);
instead of above lines you need to replace them as below-
Apexpages.Standardcontroller stdController = new Apexpages.Standardcontroller((FF);
ApexPages.StandardController sc = new ApexPages.StandardController(stdController);
FFPage sc1 = new FFPage(sc);
That doesn't look right to me - why do you need to wrap a standard controller inside another instance of a standard controller?
one line was added extra in previous code,the code should be as below-
Apexpages.Standardcontroller stdController = new Apexpages.Standardcontroller((FF);
FFPage sc1 = new FFPage(stdController);
That's the same as the OP code isn't it?
hi bob
i got the solution and get rid if that issue now.but i want to know one think which is Indigestible for me that when i run a test case for one particular class it covers the 100% code but at the deployment time i got 74% code coverage for all the class , as i deployed them earlier so why they create code coverage problem this time.
thanks
Hi kapil
i am not getting that issue now but unable to deploy the class.the red lines are not covered.
Please help me.
Thanks
Hi deepak,
I guess you are having issues while devployment because overall coverage is less then required. when you run a single class it will show you coverage for single class but when you run all test cases then it will run all classes & that should be more then 75%.
Let me explain how this works while deployment, the salesforce internally put all your test classes on production & execute those on the basis of the production enviournment so let;s say if you have some data on sandbox & these data is using by test classes then it will not be covered when you are going to deploy because data will not be available on production.