• force_rocks
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

I created a project in Force IDE using Prod credentials. Then I created an Apex Class(Class A) in IDE. The Apex Class compiles fine, but can't be copied onto the server, due to code coverage issues. So I then created another Apex Class(Class B) to test Class A. What's weird is that the IDE is trying to compile Class B on the server and not locally. This would obviously fail because Class A is not on the server yet.

 

Now I created a Sandbox for Development purpose. Here Class A and Class B compile fine, but can't be deployed onto the server, again because of the code coverage. In Class B(Test Class) I have created a object of Class A and called all the methods of it. Even then it complains Class A is 0% covered.

 

I think there is an issue with the way I have implemented the Test class.

 

Pls help.

 

Error: IncomeExt(ApexClass) -- 13 lines not tested, 0% covered.

 

Class A:

public class IncomeExt {
public Income__c q {get;set;}
public IncomeExt (ApexPages.StandardController c)
{
    controller = c;
    q = (Income__c) c.getRecord();
}

public void save()
{}

public String attachIncome()
{
    PageReference pdfPage = Page.AD672PDF;
     pdfPage.getParameters().put('id',q.id);
     Blob pdfBlob = pdfPage.getContent();
     Attachment a = new Attachment(parentId = q.id, name=q.id + '.pdf', body = pdfBlob);
    insert a;
    return('test');
}
      
      
private ApexPages.StandardController controller;      
   
}

 

 

Class B: (tester class)

@IsTest private with sharing class IncomeExtTest {
static testMethod void myPage_Test()
{
//PageReference pageRef = Page.AD672;
//Test.setCurrentPageReference(pageRef);
ApexPages.StandardController con = new ApexPages.StandardController(new Income__c());
// create an instance of the controller
//test.startTest();
IncomeExt temp1 = new IncomeExt(con);
temp1.attachIncome();
temp1.save();
//test.stopTest();
}
}



I have a Apex class and I am trying to write a Apex Test Class to test it and satisfy the 75% code coverage constraint. But the test class cannot find the constrcutor defined in the Apex class.

Apex Class:

 

public class GenAD672 {

    public Income__c q {get;set;}
   
    public GenAD672(ApexPages.StandardController c) {
        controller = c;
        q          = (Income__c) c.getRecord();
    }

 

  public Void save() {
    }

}

 

Apex Test Class:


@IsTest private with sharing class AD672PDFTests {


static testMethod void myPage_Test()
{

PageReference pageRef = Page.AD672;

Test.setCurrentPageReference(pageRef);
ApexPages.StandardController con = new ApexPages.StandardController(new Income__c());
// create an instance of the controller


IncomeEXT temp1 = new IncomeEXT(con);
//IncomeEXT temp1 = new IncomeEXT();

//temp1.save();
}
}

 

If I create the apex class object using

IncomeEXT temp1 = new IncomeEXT(con); it throws error message:

Save error: Constructor not defined: [IncomeEXT].<Constructor>(ApexPages.StandardController)

 

If I create the apex class object using

IncomeEXT temp1 = new IncomeEXT();

The instantiation is fine but when I try to call a function in the class for eg: temp1.save(); it throws the error message:

 

Save error: Method does not exist or incorrect signature: [IncomeEXT].save()

 

I'm guessing, this is because, even though the constructor in the Apex class is on my local machine Force.com IDE is using the Apex class on the Prod site which doesn't have the constructor. It's just a emply class. And the reason I can't move the file to PROD is I don't have the code coverage for it and that's why I'm writing the Test Class in the first place.

 

Pls help.

 

I have a Apex class and I am trying to write a Apex Test Class to test it and satisfy the 75% code coverage constraint. But the test class cannot find the constrcutor defined in the Apex class.

Apex Class:

 

public class GenAD672 {

    public Income__c q {get;set;}
   
    public GenAD672(ApexPages.StandardController c) {
        controller = c;
        q          = (Income__c) c.getRecord();
    }

 

  public Void save() {
    }

}

 

Apex Test Class:


@IsTest private with sharing class AD672PDFTests {


static testMethod void myPage_Test()
{

PageReference pageRef = Page.AD672;

Test.setCurrentPageReference(pageRef);
ApexPages.StandardController con = new ApexPages.StandardController(new Income__c());
// create an instance of the controller


IncomeEXT temp1 = new IncomeEXT(con);
//IncomeEXT temp1 = new IncomeEXT();

//temp1.save();
}
}

 

If I create the apex class object using

IncomeEXT temp1 = new IncomeEXT(con); it throws error message:

Save error: Constructor not defined: [IncomeEXT].<Constructor>(ApexPages.StandardController)

 

If I create the apex class object using

IncomeEXT temp1 = new IncomeEXT();

The instantiation is fine but when I try to call a function in the class for eg: temp1.save(); it throws the error message:

 

Save error: Method does not exist or incorrect signature: [IncomeEXT].save()

 

I'm guessing, this is because, even though the constructor in the Apex class is on my local machine Force.com IDE is using the Apex class on the Prod site which doesn't have the constructor. It's just a emply class. And the reason I can't move the file to PROD is I don't have the code coverage for it and that's why I'm writing the Test Class in the first place.

 

Pls help.