function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce2015Salesforce2015 

Help for Test Class

Hi Experts,

below is my Apex Class, i need test class for my below class.
I tried see my test class, but it showing 0% Code coverage


public class SendPartnerGroupRequirementsExt {
    public String RequirementID{get;set;}
    public SendPartnerGroupRequirementsExt(ApexPages.StandardController controller) {

    }    
    public PageReference SendRequest(){
        RequirementID=ApexPages.currentPage().getParameters().get('id');
        list<Partner_Group_Requirement__c> PartgroupRequrement=[select id,Name,Partner_Group__c,Request_Type__c,Document_Type__c,Due_Date__c from Partner_Group_Requirement__c where id=:RequirementID];
        list<Request__c> ReqList=new list<Request__c>();
       for(Partner_Group_Requirement__c PGR : PartgroupRequrement){
            Request__c Req=new Request__c();
            //Req.Partner_Group__c=PGR.Partner_Group__c;
            Req.Request_Type__c=PGR.Request_Type__c;
            Req.Container_Template__c=PGR.Document_Type__c;
            Req.Due_Date__c =PGR.Due_Date__c;
            ReqList.add(Req);
            
        }
        
        if(ReqList.size()>0){
          system.debug('&&&&&sample&&&&&'+ReqList);
           insert ReqList;
           for(Request__c Req : ReqList){
               Recipient__c Recp=new Recipient__c();
               //Recp.Partner_Group__c=Req.Partner_Group__c;
               Recp.Request__c=Req.id;
               insert Recp;
               system.debug('******sampletest******'+Recp);
           } 
        }
        PageReference orderPage = new PageReference('/'+RequirementID);
        orderPage.setRedirect(true);
        return orderPage;
    }
 
}




I used below page & Class
VF Page:  SendPartnerGroupRequirements
Apex Class:  SendPartnerGroupRequirementsExt

I tried below code, it showing 0% Code Coverage. Please anyone help me for creating Test Class.


@isTest
Private class SendPartnerGroupRequirementsExtTest
{

static testMethod void SendRequest() {
Partner_Group_Requirement__c TempObj1 = new Partner_Group_Requirement__c();
TempObj1.name = 'Test record';
TempObj1.Request_Type__c = 'Form';
TempObj1.Requirement__c = 'Approved';
TempObj1.Document_Type__c = 'California Transparency of Supply Chain Act';
TempObj1.Partner_Group__c = 'testsample1';
insert TempObj1;

PageReference pageRef = Page.SendPartnerGroupRequirements;
Test.setCurrentPage(pageRef);
ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(TempObj1);
ApexPages.currentPage().getParameters().put('Id',TempObj1.id);
SendPartnerGroupRequirementsExt ec = new SendPartnerGroupRequirementsExt(sc);

}

}
Salesforce2015Salesforce2015
Please find below objects & Fields.

User-added image
pconpcon
You are not actually testing anythign inside your controller.  You will need to call your controller methods and verify that the returned data is correct.
pconpcon
No, these forums are not meant for that; you'll want to post over on the AppExchange site where you can match up with a developer looking to work on your project. If you write the test code and have issue or need help, we'll gladly help, but we will not write it for you.

https://appexchange.salesforce.com/developers
pconpcon
I can give you some pointers and hopefully get you started.  I would recommend that you do some reading on testing [1] [2] [3] [4] [5] to get a better understanding.  Each of your individual tests should only tests one specific portion of you class (ie a constructor test, sendEmail test, contactSelected test, etc).  You should also have both a postitive (everything works perfectly) and a negative (things are not right) test.

Each test should follow the following structure:
  • Setup of test data. This includes creation of any data needed by your class.  Account, Contacts etc
  • Starting the test. This is calling Test.startTest() to reset the governor limits
  • Calling your class / method
  • Stopping the test.This is calling Test.stopTest() to reset the governor limits and allow for any async jobs to finish
  • Asserting that your changes have worked
    • If you have inserted/updated/deleted data, you need to query for the updates
    • Run System.assert, System.assertEquals, System.assertNotEquals to verify that you got the correct data back
[1] http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
[2] http://pcon.github.io/presentations/testing/
[3] http://blog.deadlypenguin.com/blog/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/
[4] http://blog.deadlypenguin.com/blog/testing/strategies/
[5] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm
Salesforce2015Salesforce2015
Hi pcon,

Thanks ton, it very useful to understand.
Please do one more favour, please give me links for learning Apex. Thanks in advance.

Thanks,
Manu