You need to sign in to do that
Don't have an account?
shakila G
My Apex class unable to cover by Test class?
Hi All,
Am wrote a test class for my Apex class. After that also my class not covered by 0%.
Kindly let me know where am doing the mistake?
Hi,
Kindly anyone suggests me to write a test class for this Apex class?
public class IssuedConsumable{
Dispatched_Raw_Material__c DPRM= new Dispatched_Raw_Material__c();
public list<Dispatched_Raw_Material__c> listAccount{get;set;}
{
listAccount=new list<Dispatched_Raw_Material__c>();
listAccount.add(DPRM);
}
Public void addRows()
{
Dispatched_Raw_Material__c acc = new Dispatched_Raw_Material__c();
listAccount.add(acc);
}
public PageReference saveAccount() {
for(Integer i=0; i<listAccount.size(); i++)
{
insert listAccount;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Created Successfully'));
}
Return page.IssuedConsumable;
}
}
My Test Class:
@isTest(seealldata=true)
Public class IssuedConsumable_test{
static testMethod void IssuedConsumable_test(){
GetInitialData Getdata = new GetInitialData();
list<Account> acc = Getdata.getAccount();
list<Product2> lstprod = Getdata.getProd();
list<Opportunity> Opp = Getdata.getOpp();
list<Pricebook2> lstPB = Getdata.getpricebook();
list<Pricebookentry> lststdPbe = Getdata.getstdpbe();
list<Pricebookentry> lstPbentry = new list<Pricebookentry>();
insert lstprod;
Integer indexvalue = 0;
if(lstprod.size()>0)
{
for(pricebookentry irow :lststdPbe)
{
irow.product2id = lstprod[indexvalue].id;
indexvalue++;
}
}
insert lststdPbe;
insert lstPB;
if(lstprod.size()>0)
{
for(pricebook2 irow :lstPB)
{
for(Product2 ipro : lstprod ){
Pricebookentry pbe = new Pricebookentry();
pbe.product2id = ipro.id;
pbe.pricebook2id = irow.id;
pbe.unitprice = 3000;
pbe.isActive = true;
lstPbentry.add(pbe);
}
}
}
insert lstPbentry;
insert acc[0];
Opp[0].accountId = acc[0].id;
insert Opp[0];
Opp[0].Pricebook2Id = lstPB[0].id;
update Opp[0];
OpportunityLineItem OL = new OpportunityLineItem(opportunityid=Opp[0].id, Quantity=1, unitprice=8000,
pricebookentryid=lstPbentry[0].id);
insert OL;
Tax_Master__c txm= new Tax_Master__c(CGST__c=14.00,HSN_Code__c=lstprod[0].HSN_Code__c,IGST__c=28.00,SGST__c=14.00, Start_Date__c = Date.newInstance(2017, 07, 06), End_Date__c = System.today()+2);
insert txm;
Quote Q = new Quote();
Q.Name = 'QuoteOrbit';
Q.OpportunityId = Opp[0].id;
Q.Quote_Count__c = 00000000;
Q.Quote_Number__c ='000000';
Q.Approved__c = false;
Q.Quotation_Date__c = date.newinstance(2013,3,5);
Q.Pricebook2Id = lstPB[0].id;
Q.Tax_Classification__c='IGST';
Q.Discount_Amount__c = 100;
insert Q;
Quotelineitem QL = new Quotelineitem(quoteId=Q.id,SGST__c=6, CGST__c=6,IGST__c =0,Quantity =1, Unitprice=8000,pricebookentryid=lstPbentry[0].id);
insert QL;
Project__c p = new Project__c(Name = 'NewProject',Project_Type__c = 'New PE',
Opportunity__c = Opp[0].id,
Quote__c = q.id);
insert p;
Product2 prod = new Product2(Name = 'ProdTest', CST__c = 2, Central_Excise__c = 3, VAT__c = 4,
Family = '');
insert prod;
Employee__c e = new Employee__c(Name = 'lakshmanan');
insert e;
Project_Item__c pi = new Project_Item__c(Project__c = p.id,Status__c = 'In Progress',Product__c = prod.id,
Technician_Member__c = 'suren; lakshmanan');
insert pi;
QuoteLineItem qli = new QuoteLineItem (QuoteId = q.id,PricebookEntryId = lstPbentry[0].id, Quantity = 10,
UnitPrice = 100);
insert qli;
RawMaterial__c rm1 = new RawMaterial__c(Name = 'Painting Mask',Unit__c='MM');
insert rm1;
Raw_Material_Inventory__c RW= New Raw_Material_Inventory__c(Name='Painting Mask');
insert RW ;
Dispatched_Raw_Material__c DR= new Dispatched_Raw_Material__c(Raw_Material_Inventory__c=RW.ID);
insert DR;
IssuedConsumable RMR = New IssuedConsumable();
rmr.addRows();
rmr.saveAccount();
}
}
Am wrote a test class for my Apex class. After that also my class not covered by 0%.
Kindly let me know where am doing the mistake?
Hi,
Kindly anyone suggests me to write a test class for this Apex class?
public class IssuedConsumable{
Dispatched_Raw_Material__c DPRM= new Dispatched_Raw_Material__c();
public list<Dispatched_Raw_Material__c> listAccount{get;set;}
{
listAccount=new list<Dispatched_Raw_Material__c>();
listAccount.add(DPRM);
}
Public void addRows()
{
Dispatched_Raw_Material__c acc = new Dispatched_Raw_Material__c();
listAccount.add(acc);
}
public PageReference saveAccount() {
for(Integer i=0; i<listAccount.size(); i++)
{
insert listAccount;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Created Successfully'));
}
Return page.IssuedConsumable;
}
}
My Test Class:
@isTest(seealldata=true)
Public class IssuedConsumable_test{
static testMethod void IssuedConsumable_test(){
GetInitialData Getdata = new GetInitialData();
list<Account> acc = Getdata.getAccount();
list<Product2> lstprod = Getdata.getProd();
list<Opportunity> Opp = Getdata.getOpp();
list<Pricebook2> lstPB = Getdata.getpricebook();
list<Pricebookentry> lststdPbe = Getdata.getstdpbe();
list<Pricebookentry> lstPbentry = new list<Pricebookentry>();
insert lstprod;
Integer indexvalue = 0;
if(lstprod.size()>0)
{
for(pricebookentry irow :lststdPbe)
{
irow.product2id = lstprod[indexvalue].id;
indexvalue++;
}
}
insert lststdPbe;
insert lstPB;
if(lstprod.size()>0)
{
for(pricebook2 irow :lstPB)
{
for(Product2 ipro : lstprod ){
Pricebookentry pbe = new Pricebookentry();
pbe.product2id = ipro.id;
pbe.pricebook2id = irow.id;
pbe.unitprice = 3000;
pbe.isActive = true;
lstPbentry.add(pbe);
}
}
}
insert lstPbentry;
insert acc[0];
Opp[0].accountId = acc[0].id;
insert Opp[0];
Opp[0].Pricebook2Id = lstPB[0].id;
update Opp[0];
OpportunityLineItem OL = new OpportunityLineItem(opportunityid=Opp[0].id, Quantity=1, unitprice=8000,
pricebookentryid=lstPbentry[0].id);
insert OL;
Tax_Master__c txm= new Tax_Master__c(CGST__c=14.00,HSN_Code__c=lstprod[0].HSN_Code__c,IGST__c=28.00,SGST__c=14.00, Start_Date__c = Date.newInstance(2017, 07, 06), End_Date__c = System.today()+2);
insert txm;
Quote Q = new Quote();
Q.Name = 'QuoteOrbit';
Q.OpportunityId = Opp[0].id;
Q.Quote_Count__c = 00000000;
Q.Quote_Number__c ='000000';
Q.Approved__c = false;
Q.Quotation_Date__c = date.newinstance(2013,3,5);
Q.Pricebook2Id = lstPB[0].id;
Q.Tax_Classification__c='IGST';
Q.Discount_Amount__c = 100;
insert Q;
Quotelineitem QL = new Quotelineitem(quoteId=Q.id,SGST__c=6, CGST__c=6,IGST__c =0,Quantity =1, Unitprice=8000,pricebookentryid=lstPbentry[0].id);
insert QL;
Project__c p = new Project__c(Name = 'NewProject',Project_Type__c = 'New PE',
Opportunity__c = Opp[0].id,
Quote__c = q.id);
insert p;
Product2 prod = new Product2(Name = 'ProdTest', CST__c = 2, Central_Excise__c = 3, VAT__c = 4,
Family = '');
insert prod;
Employee__c e = new Employee__c(Name = 'lakshmanan');
insert e;
Project_Item__c pi = new Project_Item__c(Project__c = p.id,Status__c = 'In Progress',Product__c = prod.id,
Technician_Member__c = 'suren; lakshmanan');
insert pi;
QuoteLineItem qli = new QuoteLineItem (QuoteId = q.id,PricebookEntryId = lstPbentry[0].id, Quantity = 10,
UnitPrice = 100);
insert qli;
RawMaterial__c rm1 = new RawMaterial__c(Name = 'Painting Mask',Unit__c='MM');
insert rm1;
Raw_Material_Inventory__c RW= New Raw_Material_Inventory__c(Name='Painting Mask');
insert RW ;
Dispatched_Raw_Material__c DR= new Dispatched_Raw_Material__c(Raw_Material_Inventory__c=RW.ID);
insert DR;
IssuedConsumable RMR = New IssuedConsumable();
rmr.addRows();
rmr.saveAccount();
}
}
Kindly give a suggestion. I want to complete this in High priority.
I have entered all the mandatory information even though am getting the below error.
Go to salesforce tab and see what all are required and insert those into Raw_Material_Inventory__c object in test class
Raw_Material_Inventory__c RW= New Raw_Material_Inventory__c(Name='Painting Mask');
// Add all required fileds and run the test class
insert RW ;
If you can share the code for Raw_Material_Inventory__c i will rewrite it for you
@isTest(seealldata=true)
Public class IssuedConsumable_test{
static testMethod void IssuedConsumable_test(){
GetInitialData Getdata = new GetInitialData();
list<Account> acc = Getdata.getAccount();
list<Product2> lstprod = Getdata.getProd();
list<Opportunity> Opp = Getdata.getOpp();
list<Pricebook2> lstPB = Getdata.getpricebook();
list<Pricebookentry> lststdPbe = Getdata.getstdpbe();
list<Pricebookentry> lstPbentry = new list<Pricebookentry>();
insert lstprod;
Integer indexvalue = 0;
if(lstprod.size()>0)
{
for(pricebookentry irow :lststdPbe)
{
irow.product2id = lstprod[indexvalue].id;
indexvalue++;
}
}
insert lststdPbe;
insert lstPB;
if(lstprod.size()>0)
{
for(pricebook2 irow :lstPB)
{
for(Product2 ipro : lstprod ){
Pricebookentry pbe = new Pricebookentry();
pbe.product2id = ipro.id;
pbe.pricebook2id = irow.id;
pbe.unitprice = 3000;
pbe.isActive = true;
lstPbentry.add(pbe);
}
}
}
insert lstPbentry;
insert acc[0];
Opp[0].accountId = acc[0].id;
insert Opp[0];
Opp[0].Pricebook2Id = lstPB[0].id;
update Opp[0];
OpportunityLineItem OL = new OpportunityLineItem(opportunityid=Opp[0].id, Quantity=1, unitprice=8000,
pricebookentryid=lstPbentry[0].id);
insert OL;
Tax_Master__c txm= new Tax_Master__c(CGST__c=14.00,HSN_Code__c=lstprod[0].HSN_Code__c,IGST__c=28.00,SGST__c=14.00, Start_Date__c = Date.newInstance(2017, 07, 06), End_Date__c = System.today()+2);
insert txm;
Quote Q = new Quote();
Q.Name = 'QuoteOrbit';
Q.OpportunityId = Opp[0].id;
Q.Quote_Count__c = 00000000;
Q.Quote_Number__c ='000000';
Q.Approved__c = false;
Q.Quotation_Date__c = date.newinstance(2013,3,5);
Q.Pricebook2Id = lstPB[0].id;
Q.Tax_Classification__c='IGST';
Q.Discount_Amount__c = 100;
insert Q;
Quotelineitem QL = new Quotelineitem(quoteId=Q.id,SGST__c=6, CGST__c=6,IGST__c =0,Quantity =1, Unitprice=8000,pricebookentryid=lstPbentry[0].id);
insert QL;
Project__c p = new Project__c(Name = 'NewProject',Project_Type__c = 'New PE',
Opportunity__c = Opp[0].id,
Quote__c = q.id);
insert p;
Product2 prod = new Product2(Name = 'ProdTest', CST__c = 2, Central_Excise__c = 3, VAT__c = 4,
Family = '');
insert prod;
Employee__c e = new Employee__c(Name = 'lakshmanan');
insert e;
Project_Item__c pi = new Project_Item__c(Project__c = p.id,Status__c = 'In Progress',Product__c = prod.id,
Technician_Member__c = 'suren; lakshmanan');
insert pi;
QuoteLineItem qli = new QuoteLineItem (QuoteId = q.id,PricebookEntryId = lstPbentry[0].id, Quantity = 10,
UnitPrice = 100);
insert qli;
RawMaterial__c rm1 = new RawMaterial__c(Name = 'Painting Mask',Unit__c='MM');
insert rm1;
Raw_Material_Inventory__c RW= New Raw_Material_Inventory__c(Name='Painting Mask',
RawMaterial__c=rm1.ID,Min_Quantity_Check__c=True,Minimum_Stock_Quantity__c=100);
insert RW ;
Dispatched_Raw_Material__c DR= new Dispatched_Raw_Material__c(
Raw_Material_Inventory__c=RW.ID);
insert DR;
IssuedConsumable RMR = New IssuedConsumable();
rmr.addRows();
rmr.saveAccount();
}
}
@isTest(seealldata=true)
=========
public class IssuedConsumable{
Dispatched_Raw_Material__c DPRM= new Dispatched_Raw_Material__c();
public list<Dispatched_Raw_Material__c> listAccount{get;set;}
{
listAccount=new list<Dispatched_Raw_Material__c>();
listAccount.add(DPRM);
}
Public void addRows()
{
Dispatched_Raw_Material__c acc = new Dispatched_Raw_Material__c();
listAccount.add(acc);
}
public PageReference saveAccount() {
for(Integer i=0; i<listAccount.size(); i++)
{
insert listAccount;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Created Successfully'));
}
Return page.IssuedConsumable;
}
}