+ Start a Discussion
Soundar Raj PonpandiSoundar Raj Ponpandi 

Test Class Cover for sample class ?


Can you cover a test class for this sample class
Description : Generate PDF in Sales order Details Page.

public with sharing class GD_SalesOrderPrintableView {
    public string so_Id = apexpages.currentpage().getparameters().get('id');
    public List<GD_Order_Line_Item__c> accList{get;set;}
    public List<GD_Address__c> addList{get;set;}
    set<id> accId = New set<id>();
    public GD_SalesOrderPrintableView (ApexPages.StandardController controller){
        accList = [select id,name ,GD_Unit_Price__c,GD_Total_Amount_Formula__c, GD_Quantity__c,GD_Item__r.name, GD_Vat__c, GD_Discount__c from GD_Order_Line_Item__c where GD_Sales_Order__c =: so_Id];
        GD_Order__c so = [select id,name from GD_Order__c where id =:so_Id]; 
        string acc = so.GD_Account__c;
        system.debug('Account Name ++ ' + acc);
        addList = [select id,name,GD_Type__c from GD_Address__c where id =:acc and  GD_Type__c = 'BILL_TO' Limit 1];

ANUTEJANUTEJ (Salesforce Developers) 
Hi Soundar,

Were you getting any errors while running the test class?? For writing the test class you will have to give all the values so that you can cover all the lines and all the possible scenarios.

I hope this helps.

Soundar Raj PonpandiSoundar Raj Ponpandi
Dear AnuTEJ,

Hearty thanks for your response.

here is my Test class it's showing no method passing to the test class.
public class GD_SalesOrderPrintableViewTest {

    public static void testData(){
        Account acc = new Account(Name = 'TestAccountName'); 
        insert acc;
        GD_Address__c address = new GD_Address__c(GD_account__c = acc.id, GD_Address_1__c = 'address 1', GD_Address_2__c = 'address 2', GD_Address_3__c = 'address 3');
        insert address;
        GD_Order_Line_Item__c oli = new GD_Order_Line_Item__c(name = 'test',GD_Unit_Price__c = 10, GD_Quantity__c = 5, GD_Vat__c = 10, GD_Discount__c = 10);
        insert oli;
        GD_Order__c ord = new GD_Order__c(GD_Account__c = acc.id);
        insert ord;
        ApexPages.StandardController sc = new ApexPages.standardController(address);
        GD_SalesOrderPrintableView controller = new GD_SalesOrderPrintableView(sc);