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

How to increase the code coverage percentage in TestCase
Hi All,
I have a requirement wherein, I need to create the packages in the Invoice, when the record type of the Items is 'package' in the Invoice_Line_Item, then the required number of packages are to be created.
I am getting the desired output, but when I have written the TestCase, the code coverage is 42%. But, in order to migrate the code on to Live, we need a minimum code coverage of 75%.
So, could anyone suggest a solution for the above mentioned problem. I am posting both the Class and TestCase, do suggest a solution.
Apex Class
public class MyClass
{
public static void createPackage(Invoice__c [] inv)
{
for(Invoice__c i : inv)
{
Invoice_Line_Item__c[] a1;
a1 = [select id,name,Item__r.RecordTypeId from Invoice_Line_Item__c where invoice_number__c =:i.id and Item__r.RecordTypeId='01290000000K8Ba'];
Integer j=a1.size();
for(Invoice_Line_Item__c a2 : a1)
{
if((i.Create_Package__c==true)||(i.Status__c=='FULLY PAID'))
{
for(Integer k=1;k<=j;k++)
{
if(i.Package_Status__c!='Package Created')
{
Package__c p1 = new Package__c();
p1.RecordTypeId='01290000000Xn01';
p1.invoice__c = i.id;
p1.Invoice_Line_Item__c = a2.id;
p1.patient__c= i.Patient__c;
insert p1;
}
}
i.Package_Status__c='Package Created';
}
}
}
}
}
Test Case
@isTest
private class MyClassTestCase {
static testMethod void createPackage() {
item__c v =[select id,name from item__c limit 1];
// invoice__c i = [select id,name, Patient__c from invoice__c limit 1];
invoice__c i = [select id,name,Create_Package__c, Status__c, Patient__c,
Package_Status__c from invoice__c limit 1];
Invoice_Line_Item__c il = new Invoice_Line_Item__c ();
il.invoice_number__c = i.id;
il.item__c = v.id;
insert il;
if((i.Create_Package__c==true)||(i.Status__c=='FULLY PAID'))
{
if(i.Package_Status__c!='Package Created')
{
Package__c p1 = new Package__c();
p1.RecordTypeId='01290000000Xn01';
p1.invoice__c = i.id;
p1.Invoice_Line_Item__c = il.id;
p1.patient__c= i.Patient__c;
insert p1;
}
i.Package_Status__c='Package Created';
}
}
}
Do suggest a solution and guide me in the right path.
Thanks and Regards
Arun
Hello Friend
The case which you have return is wrong. The correct test case should be as follow:
Hope this helps
Regards
Raumil Setalwad