You need to sign in to do that
Don't have an account?

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;
}
}
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;
}
}
All Answers
Your code was perfect but missed few parameters in test class, so please use my code
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh