You need to sign in to do that
Don't have an account?
utz1
To cover test class for if condition
Hello, I want to cover my test class for If condition.
@isTest(seeAllData = true)
public class CreateInvoiceDelTest {
public static testMethod void testManipulateOrders(){
Account a = new Account();
a.Name = 'Test Account';
a.Price_Book__c = '01s8E000000DOci';
insert a;
Contact c = new Contact();
c.LastName='test';
insert c;
Product2 p = new Product2();
p.Name = ' Test Product ';
p.Description='Test Product Entry 1';
p.productCode = 'ABC';
p.isActive = true;
p.Family = 'Blackbox';
insert p;
Pricebook2 standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
PricebookEntry standardPrice = new PricebookEntry();
standardPrice.Pricebook2Id = standardPb.Id;
standardPrice.Product2Id = p.Id;
standardPrice.UnitPrice = 1;
standardPrice.IsActive = true;
standardPrice.UseStandardPrice = false;
insert standardPrice ;
Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
PricebookEntry pbe = [ SELECT Id,Product2Id,Pricebook2Id,UnitPrice FROM PricebookEntry WHERE isActive=true LIMIT 1 ];
Order od = new Order();
od.Name = 'Test';
od.AccountId = a.Id;
od.status = 'Draft';
od.Your_Order_Reference__c = '123';
od.EffectiveDate = system.today();
insert od;
Invoice__c i = new Invoice__c();
i.Account__c = a.Id;
i.Contact__c = c.Id;
i.Order__c = od.Id;
i.Your_Reference__c = od.Your_Order_Reference__c;
insert i;
Delivery_Notes__c d = new Delivery_Notes__c();
d.Account__c = a.id;
d.Contact__c = c.Id;
d.Your_Reference__c = od.Your_Order_Reference__c;
d.Order__c = od.Id;
insert d;
test.StartTest();
od.Status = 'Closed Won';
system.debug('Test od.Status------>'+od.Status);
if(od.Status == 'Closed Won' && od.Invoice__r.size() == 0){
Invoice__c i2 = new Invoice__c();
system.debug('Invoice__C Created---->'+i2);
}
/* else if(od.Status != 'Closed Won' && od.Invoice__r.size() >= 0)
{
system.debug('Error');
}*/
if(od.Status == 'Closed Won' && od.Delivery_Notes__r.size() == 0 ){
Delivery_Notes__c d1 = new Delivery_Notes__c();
}
update od;
test.StopTest();
}
public static testMethod void testManipulateOrders1(){
Account a = new Account();
a.Name = 'Test Account';
a.Price_Book__c = '01s8E000000DOci';
insert a;
Contact c = new Contact();
c.LastName='test';
insert c;
Product2 p = new Product2();
p.Name = ' Test Product ';
p.Description='Test Product Entry 1';
p.productCode = 'ABC';
p.isActive = true;
p.Family = 'Blackbox';
insert p;
Pricebook2 standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
PricebookEntry standardPrice = new PricebookEntry();
standardPrice.Pricebook2Id = standardPb.Id;
standardPrice.Product2Id = p.Id;
standardPrice.UnitPrice = 1;
standardPrice.IsActive = true;
standardPrice.UseStandardPrice = false;
insert standardPrice ;
Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
PricebookEntry pbe = [ SELECT Id,Product2Id,Pricebook2Id,UnitPrice FROM PricebookEntry WHERE isActive=true LIMIT 1 ];
Order od = new Order();
od.Name = 'Test';
od.AccountId = a.Id;
od.status = 'Draft';
od.Your_Order_Reference__c = '123';
od.EffectiveDate = system.today();
insert od;
Invoice__c i = new Invoice__c();
i.Account__c = a.Id;
i.Contact__c = c.Id;
i.Order__c = od.Id;
i.Your_Reference__c = od.Your_Order_Reference__c;
insert i;
Delivery_Notes__c d = new Delivery_Notes__c();
d.Account__c = a.id;
d.Contact__c = c.Id;
d.Your_Reference__c = od.Your_Order_Reference__c;
d.Order__c = od.Id;
insert d;
test.StartTest();
od.Status = 'Draft';
system.debug('Test od.Status------>'+od.Status);
if(od.Status != 'Closed Won' && od.Invoice__r.size() >= 0){
system.debug('Error');
}
if(od.Status != 'Closed Won' && od.Delivery_Notes__r.size() >= 0 ){
system.debug('Error');
}
update od;
test.StopTest();
}
}
My trigger is:
Invoice__c newInvoice1 = new Invoice__c();
System.debug('New Inovice Is Created');
// newInvoice.Name ='Invoice';
newInvoice1.Account__c = o.AccountId;
newInvoice1.Order__c= o.Id;
newInvoice1.Your_Reference__c= o.Your_Order_Reference__c;
newInvoice1.Contact__c= o.Contact__c;
// newInvoice.Status__c = 'Pending';
// newInvoice.Pricebook2Id = q.Pricebook2Id;
insert newInvoice1;
System.debug('Invoices Created with data'+newInvoice1);
I am not able to cover these statements in my test clss
Thanks & Regrads,
Utz
@isTest(seeAllData = true)
public class CreateInvoiceDelTest {
public static testMethod void testManipulateOrders(){
Account a = new Account();
a.Name = 'Test Account';
a.Price_Book__c = '01s8E000000DOci';
insert a;
Contact c = new Contact();
c.LastName='test';
insert c;
Product2 p = new Product2();
p.Name = ' Test Product ';
p.Description='Test Product Entry 1';
p.productCode = 'ABC';
p.isActive = true;
p.Family = 'Blackbox';
insert p;
Pricebook2 standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
PricebookEntry standardPrice = new PricebookEntry();
standardPrice.Pricebook2Id = standardPb.Id;
standardPrice.Product2Id = p.Id;
standardPrice.UnitPrice = 1;
standardPrice.IsActive = true;
standardPrice.UseStandardPrice = false;
insert standardPrice ;
Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
PricebookEntry pbe = [ SELECT Id,Product2Id,Pricebook2Id,UnitPrice FROM PricebookEntry WHERE isActive=true LIMIT 1 ];
Order od = new Order();
od.Name = 'Test';
od.AccountId = a.Id;
od.status = 'Draft';
od.Your_Order_Reference__c = '123';
od.EffectiveDate = system.today();
insert od;
Invoice__c i = new Invoice__c();
i.Account__c = a.Id;
i.Contact__c = c.Id;
i.Order__c = od.Id;
i.Your_Reference__c = od.Your_Order_Reference__c;
insert i;
Delivery_Notes__c d = new Delivery_Notes__c();
d.Account__c = a.id;
d.Contact__c = c.Id;
d.Your_Reference__c = od.Your_Order_Reference__c;
d.Order__c = od.Id;
insert d;
test.StartTest();
od.Status = 'Closed Won';
system.debug('Test od.Status------>'+od.Status);
if(od.Status == 'Closed Won' && od.Invoice__r.size() == 0){
Invoice__c i2 = new Invoice__c();
system.debug('Invoice__C Created---->'+i2);
}
/* else if(od.Status != 'Closed Won' && od.Invoice__r.size() >= 0)
{
system.debug('Error');
}*/
if(od.Status == 'Closed Won' && od.Delivery_Notes__r.size() == 0 ){
Delivery_Notes__c d1 = new Delivery_Notes__c();
}
update od;
test.StopTest();
}
public static testMethod void testManipulateOrders1(){
Account a = new Account();
a.Name = 'Test Account';
a.Price_Book__c = '01s8E000000DOci';
insert a;
Contact c = new Contact();
c.LastName='test';
insert c;
Product2 p = new Product2();
p.Name = ' Test Product ';
p.Description='Test Product Entry 1';
p.productCode = 'ABC';
p.isActive = true;
p.Family = 'Blackbox';
insert p;
Pricebook2 standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
PricebookEntry standardPrice = new PricebookEntry();
standardPrice.Pricebook2Id = standardPb.Id;
standardPrice.Product2Id = p.Id;
standardPrice.UnitPrice = 1;
standardPrice.IsActive = true;
standardPrice.UseStandardPrice = false;
insert standardPrice ;
Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
PricebookEntry pbe = [ SELECT Id,Product2Id,Pricebook2Id,UnitPrice FROM PricebookEntry WHERE isActive=true LIMIT 1 ];
Order od = new Order();
od.Name = 'Test';
od.AccountId = a.Id;
od.status = 'Draft';
od.Your_Order_Reference__c = '123';
od.EffectiveDate = system.today();
insert od;
Invoice__c i = new Invoice__c();
i.Account__c = a.Id;
i.Contact__c = c.Id;
i.Order__c = od.Id;
i.Your_Reference__c = od.Your_Order_Reference__c;
insert i;
Delivery_Notes__c d = new Delivery_Notes__c();
d.Account__c = a.id;
d.Contact__c = c.Id;
d.Your_Reference__c = od.Your_Order_Reference__c;
d.Order__c = od.Id;
insert d;
test.StartTest();
od.Status = 'Draft';
system.debug('Test od.Status------>'+od.Status);
if(od.Status != 'Closed Won' && od.Invoice__r.size() >= 0){
system.debug('Error');
}
if(od.Status != 'Closed Won' && od.Delivery_Notes__r.size() >= 0 ){
system.debug('Error');
}
update od;
test.StopTest();
}
}
My trigger is:
Invoice__c newInvoice1 = new Invoice__c();
System.debug('New Inovice Is Created');
// newInvoice.Name ='Invoice';
newInvoice1.Account__c = o.AccountId;
newInvoice1.Order__c= o.Id;
newInvoice1.Your_Reference__c= o.Your_Order_Reference__c;
newInvoice1.Contact__c= o.Contact__c;
// newInvoice.Status__c = 'Pending';
// newInvoice.Pricebook2Id = q.Pricebook2Id;
insert newInvoice1;
System.debug('Invoices Created with data'+newInvoice1);
I am not able to cover these statements in my test clss
Thanks & Regrads,
Utz