-1

controller class.

public class ExhibitAadminTier {
    public list<Min_Tier_threshold__c> accon{get;set;}
    public Min_Tier_threshold__c agnt{get;set;}
    public Integer mintier{set;get;}
    public id tobeEdited{get; set;} 
    public boolean editSection {get;set;}
    public ApexPages.StandardController stand;
    Public String retURL{get;set;}

    public ExhibitAadminTier(apexpages.standardcontroller controller )
    {
        retURL = ApexPages.currentPage().getParameters().get('retURL');
        this.stand=controller;
        tobeEdited = controller.getId();
        agnt = new Min_Tier_threshold__c();
        accon= [select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c]; 
    }

    public PageReference EdittheSection()
    {
        PageReference ref=new PageReference('/apex/ExhibitAadminTier1?retURL=/apex/ExhibitAAdmin');
        ref.setRedirect(true);
        update accon;
        return ref;
    }

    private void LoadData()
    {
        accon= [select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c WHERE (owner.id =: userinfo.getuserid())];
    }

    public void save1()
    {
        update accon;
    }

    public string deleteid{get;set;}

    public void DeleteTier()
    {
        Min_Tier_threshold__c del_task=new Min_Tier_threshold__c (id=deleteid);
        delete del_task;
        accon=[select id,Name,SMS_Threshold__c,SMS_Tier__c,SMS_Tier_Description__c from Min_Tier_threshold__c];
    }

    public pagereference saveRecord()
    {
        List<Min_Tier_threshold__c> discLocal=accon.clone() ;
        List<Min_Tier_threshold__c> discLocal2=new List<Min_Tier_threshold__c>(accon);
        integer i=0;
        for(Min_Tier_threshold__c Tier:accon){
            if(Tier.SMS_Threshold__c==null && Tier.SMS_Tier__c ==null && Tier.SMS_Tier_Description__c==null )
            {
                discLocal2.remove(i);
            }
            else if(Tier.SMS_Threshold__c==null || Tier.SMS_Tier__c ==null || Tier.SMS_Tier_Description__c==null )
            {
                ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must enter all required fields');
                ApexPages.addMessage(msg);
                return null;
            }
            i++;
        }
        upsert discLocal2; 
        PageReference pageRef = new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
        pageref.setRedirect(true);
        return pageref; 
    }

    public PageReference cancel()  
    {
        PageReference pg1=new PageReference('/apex/ExhibitAadminTier?retURL=/apex/ExhibitAAdmin');
        pg1.setRedirect(true);
        return pg1;
    }  

    public void addrow()
    {
        Min_Tier_threshold__c proTier = new Min_Tier_threshold__c();
        proTier .SMS_Threshold__c= (agnt.SMS_Threshold__c);
        proTier .SMS_Tier__c =(agnt.SMS_Tier__c );
        proTier .SMS_Tier_Description__c=(agnt.SMS_Tier_Description__c);
        accon.add(proTier );
    }  
}

For this class I wrote this test class but this is not working...some one help me on this.

@isTest//(SeeAllData=true)
private class test_ExhibitAadminTier {
    //boolean editSection = true;
    static testMethod void test_ExhibitAadminTier(){
        Min_Tier_threshold__c min1 = new Min_Tier_threshold__c();
        min1.name='test1';
        min1.SMS_Threshold__c=100.00;
        min1.SMS_Tier__c='test2';
        min1.SMS_Tier_Description__c ='test3';
        insert min1;
        PageReference pageRef = Page.ExhibitAadminTier; // Adding VF page Name here
        pageRef.getParameters().put('id', String.valueOf(min1.id));//for page reference
        Test.setCurrentPage(pageRef);
        ApexPages.currentPage().getParameters().put('RecordType','ExhibitAadminTier');
        ApexPages.StandardController sc = new ApexPages.standardController(min1);
        ExhibitAadminTier controller = new ExhibitAadminTier(sc);
        controller.save1();
        controller.DeleteTier();
        controller.saveRecord();
        controller.addrow();
    }
}
3
  • Hi Mona, It will be helpful if you can post your entire code. It will help debugging the issue as from this code I see that you are not calling your EdittheSection method and the controller is also not Initialized in the test class. – manjit5190 Sep 27 '15 at 10:12
  • Hi manjit this my controller-- – sfdc.sdfc Sep 27 '15 at 11:10
  • The very first of code public list accon{get;set;} doesn't seems right (unless you have a class named list). Also you are not calling controller.EditTheSection(); method. While writing test classes it is necessary to write them in the way you expect user behavior and call the methods according to that. So if user views the page and clicks load_button then a method associated with _load button should be called. Calling random methods in the controller will not cover the classes. In your case you are not calling EditTheSection Method hence it is not covered. – manjit5190 Sep 27 '15 at 11:53
1

following code will help you:

public PageReference add() {
          insert technology;
          return null;
        }

//test class for page reference method

public static testMethod void testMyController() {


PageReference pageRef = Page.yourPageName;

Test.setCurrentPage(pageRef);

MyController controller = new MyController();
controller.add();

}
1
  • Hi Ajay, thanka for your reply.but i already done that one.it is not working. – sfdc.sdfc Sep 28 '15 at 9:07
0

What exactly are you trying to achieve with the test code? Your EdittheSection() method returns a PageReference, and your test class creates a PageReference. At no point does your test class exercise any of the code in your controller.

I would suggest that you make your test class call EdittheSection() and assert that its return value (ref) is correct. See this post for an explanation: How to assert a PageReference in Test Method for Visualforce Controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.