+ Start a Discussion
Girbson Bijou 7Girbson Bijou 7 

Test an Apex Class

Helpo to create the Test class for this Controller please

public with sharing class InventorySearch { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearch( ) { 

public void search(){ 
string searchquery= 'select  Item_Full_Name__c,  UM__c,   On_Hand__c,  Pending__c,  Available__c FROM Articles_Containers__c  WHERE Item_Full_Name__c like \'%'+searchstring+'%\' AND On_Hand__c >0  Limit 20';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 

}
Best Answer chosen by Girbson Bijou 7
sfdcMonkey.comsfdcMonkey.com
your test class execution failed, click on view to check error msg, provide all requred fields value in test class data for Articles_Containers__c object 

All Answers

sfdcMonkey.comsfdcMonkey.com
HI Use below test class for 100% code coverge
@isTest 
public class InventorySearchTest {
    static testMethod void testMethod1(){
	  // Perform DML here only
	      Articles_Containers__c ac = new Articles_Containers__c();
		   ac.Name = 'test'; // if name is auto number, then remove this line 
		   ac.Item_Full_Name__c = 'testFullName';
		   ac.On_Hand__c = 5;
		  // ***** add test data here for all required fields here 
           
		   insert ac;
		   
		   InventorySearch Inv = new InventorySearch();
		     Inv.searchstring = 'testFullName';
			 Inv.search();
			 Inv.clear();
            
        }
}
i hope it helps you.
  Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
 
Girbson Bijou 7Girbson Bijou 7
Hi piyush_soni, Thank you for replying
The test class does not work. 0/1 method pass.
Girbson Bijou 7Girbson Bijou 7
User-added image
sfdcMonkey.comsfdcMonkey.com
your test class execution failed, click on view to check error msg, provide all requred fields value in test class data for Articles_Containers__c object 
This was selected as the best answer