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
KruzKruz 

Test class for select SOQL Query

Hello,

Can you please help me for writing test class for Select SOQL Query/ How to cover Select SOQL Query in Test Class
My Full Code is;

public class AccessManageCS {

             public page_access__c instanceUser, instancePro, instanceOrg;
             page_access__c pc = new page_access__c();
            // Transient Integer currentTotal;
             public AccessManageCS()
             {   
             }
             public SObject CSValues()
             {
                pc= [select Expire_date__c,License_Key__c,License_no__c,License_Type__c,Module_Name__c,Org_ID__c,Perpetual__c,Read_Only__c,Tabs__c,User_ID__c from page_access__c];
                system.debug('Page_Access_Detail'+pc);
                return pc;
             }      
}

Thank You!
Abhishek BansalAbhishek Bansal
Hi Kruz,

In order to cover the SOQL in our test class we need to setup the test data that is being queried in the SOQL. In your case the test class will look something like below:
@isTest(SeeAllData=false)
private class AccessManageCSTest {
	static testMethod void testMethod() {
		page_access__c testPageAccess = new page_access__c();
		testPageAccess.Name = 'Page Access';
		//Enter all the required fields of the object page_access__c here
		
		insert testPageAccess;
		
		Test.startTest();
			AccessManageCS testAccessManage = new AccessManageCS();
			testAccessManage.CSValues();
		Test.stopTest();
	}
}


Please let me know if you need any further help on this.

Thanks,
Abhishek Bansal.

KruzKruz
Thank you Abhishek Bansal!