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
dhruv aroradhruv arora 

help me in writting test class for this

public class abcd{
    public FA_Attestation__c att{set;get;}
    ApexPages.StandardController std;
    public boolean flag {get;set;}
    public id UserCheck {get;set;}
    public boolean flag1 {get;set;}
    public abcd(ApexPages.StandardController FAA2)
    {
        att = (FA_Attestation__c)FAA2.getRecord();
        flag1 = false;
        if(att.Confirmation__c == true)
        {
            flag = true;
        }
        //att =  new FA_Attestation__c();
        //std = FAA2;
    }
    

    public void saveform()
    {
    ApexPages.Message myMsg = new  ApexPages.Message(ApexPages.Severity.ERROR,'Please Check the Are you sure you want to submit the form? ' );        
        ApexPages.Message myMsg1 = new  ApexPages.Message(ApexPages.Severity.ERROR,'Please enter your signature in User Name field' );
        UserCheck = att.user_name__c;
        if(att.Confirmation__c == false && UserCheck == null)
        {   
            ApexPages.addMessage(myMsg);         
            ApexPages.addMessage(myMsg1);             
        }
        else if (att.Confirmation__c == false)
        {            
            ApexPages.addMessage(myMsg); 
        }
        else if (UserCheck == null)
        {            
            ApexPages.addMessage(myMsg1); 
        }
        else
        {
            if(flag1 == false)
            {
                update att;                
            }
            flag1 = true;
            flag = true;
           // std.save();
        }
    }
}
DixitDixit
Make a pageReference instance for your visualforce and your stnd controller. 
Make a register and assign that register to your stndr controller then run the methods in your controller and that's it. 

I have this example:
 
@isTest

public class SimuladorAperturas_Test {

    public static testMethod void testController(){


   simulacion__c sim = new simulacion__c();
        sim.Metros_Cuadrados__c = 1000;
        sim.Frontera__c = 'No';
        sim.Zona_Geografica__c = 'North';
        insert sim;

test.startTest();
 
         //my standard controller
         ApexPages.standardController stndController = new apexPages.standardController(sim); //the record i just created of a custom object
        pageReference pdfsimulacion = new pageReference('/apex/pdfSimulacion'); //my visualforce which use the standardcontroller
        pdfsimulacion.getParameters().put('id', sim.id); //i put the id parameter in the visualforce url
    
     //my extension
   pdfSimulacion_Extension pdfcontroller = new pdfSimulacion_Extension(stndController);

   //methods of my extension
pdfcontroller.method();

test.stopTest();
    }
}


This is just a part of my code, try to adapt it to yours

 
Amit Chaudhary 8Amit Chaudhary 8
You write a test class for this the same way that you would any other:

- Set up some data for the controller to access (in this case it looks like A_Attestation__crecords)
- Instantiate the standardController -
- Execute a method/methods
- Verify the behaviour with asserts.

The fact that the class is used as a controller is fairly immaterial.

Please try below code as sample code
@isTest

public class abcdTest 
{

    public static testMethod void testController()
	{
		FA_Attestation__c  FA = new FA_Attestation__c();
		// Add all required field here
		insert FA;
		
		
		test.startTest();

			ApexPages.standardController stndController = new apexPages.standardController(FA); 
			abcd obj = new abcd(stndController);
			obj.saveform();
			

		test.stopTest();
    }
}

Let us know if this will help you