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
Girbson Bijou 7Girbson Bijou 7 

Test Passed but code coverage is 0%

Why the coverage is 0% while the test passed?
Here is my class

public class InventoryReport {

      public List<AggregateResult> allproduct{get;set;}

     public InventoryReport() {

   allproduct = [      
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
      WHERE IsOpened__c = 1
      GROUP BY Product_Hiden_Name__c , UM__c 
      HAVING SUM(On_Hand__c) >0 
      ORDER BY Product_Hiden_Name__c, UM__c limit 1000];
      }
}

The test is:

@Istest(SeeAllData=true)
public class InventoryReportTest{
static testMethod void TestInventoryReport(){
 Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert c;
          
          ac.Product__c=p.ID;
           ac.Unit_Weight__c = 45; 
           ac.Unit_Cost__c = 87;
            ac.Container__c= c.ID;
             ac.Number__c = 55;
            ac.UM__c ='UNIT(S)';    
           ac.Local_ID__c = 7888;
           ac.Comments__c = 'UNIT(S)';
           ac.Purpose__c='Consignment';
           ac.Condition__c= 'New';
           insert ac;   
}
}
 
Best Answer chosen by Girbson Bijou 7
sfdcMonkey.comsfdcMonkey.com
Hi try folloing test class :
@Istest(SeeAllData=true)
public class InventoryReportTest{
static testMethod void TestInventoryReport(){
 Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert c;
          
		  ac.Product__c=p.ID;
		  ac.Unit_Weight__c = 45; 
		  ac.Unit_Cost__c = 87;
		  ac.Container__c= c.ID;
			ac.Number__c = 55;
			ac.UM__c ='UNIT(S)';    
		   ac.Local_ID__c = 7888;
		   ac.Comments__c = 'UNIT(S)';
		   ac.Purpose__c='Consignment';
		   ac.Condition__c= 'New';
		   ac.IsOpened__c = 1;
		   ac.On_Hand__c = 50;
		   
		   
           insert ac;

     	InventoryReport oInventoryReport = new InventoryReport();	   
}
}
Thanks, let us know if it helps you
 

All Answers

sfdcMonkey.comsfdcMonkey.com
Hi try folloing test class :
@Istest(SeeAllData=true)
public class InventoryReportTest{
static testMethod void TestInventoryReport(){
 Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert c;
          
		  ac.Product__c=p.ID;
		  ac.Unit_Weight__c = 45; 
		  ac.Unit_Cost__c = 87;
		  ac.Container__c= c.ID;
			ac.Number__c = 55;
			ac.UM__c ='UNIT(S)';    
		   ac.Local_ID__c = 7888;
		   ac.Comments__c = 'UNIT(S)';
		   ac.Purpose__c='Consignment';
		   ac.Condition__c= 'New';
		   ac.IsOpened__c = 1;
		   ac.On_Hand__c = 50;
		   
		   
           insert ac;

     	InventoryReport oInventoryReport = new InventoryReport();	   
}
}
Thanks, let us know if it helps you
 
This was selected as the best answer
mukesh guptamukesh gupta
Hi,

Your code was perfect but missed few parameters in test class, so please use my code 
 
@Istest(SeeAllData=true)
public class InventoryReportTest{
static testMethod void TestInventoryReport(){
 Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert c;
          
          ac.Product__c=p.ID;
	  ac.Unit_Weight__c = 45; 
          ac.Unit_Cost__c = 87;
          ac.Container__c= c.ID;
          ac.Number__c = 55;
          ac.UM__c ='UNIT(S)';    
          ac.Local_ID__c = 7888;
          ac.Comments__c = 'UNIT(S)';
          ac.Purpose__c='Consignment';
          ac.Condition__c= 'New';
	
	///you missed below parameter ////

	  ac.Product_Hiden_Name__c = 'test';
	  ac.IsOpened__c =1;	
	  ac.Available__c= 100;
          ac.On_Hand__c= 100;	
	  ac.Pending__c= 50;			
         	

          insert ac;   
}
}

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
 
Girbson Bijou 7Girbson Bijou 7
And It works. thank you!