You need to sign in to do that
Don't have an account?
bhaveshkjogi
Test method for " return statement "
Hi,
how can i write test case for "return 'testing' ; "
my code :
global override virtual string Tax()
{
if(loQuote.size() < 1)
return 'testing';
}
I want to write test case of this. please any one write for me ...how to write test case of " return" .
You just make sure that this list
loQuote.size() == 0 ,
Then the return statement will be automatically executed.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
My class detail:
global List<Quote> loQuote = null;
global virtual void Initialize()
{
loQuote = [select Id, OpportunityId,
Quote_Date__c, Pricebook2Id, Tax_Date__c, Tax_Now_Status__c, Non_Taxable__c, TotalPrice,
ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry,
BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingHandling,
(select Id, Pricebookentry.product2.ProductCode, Description, Pricebookentry.product2,
Quantity, TotalPrice, Sales_Tax_Amount__c, Rate__c, Sales_Tax_Details__c, UnitPrice from QuoteLineItems)
from Quote where id =:apCurPage];
if(0 == loQuote.size())
{
loQuote = new List<Quote>();
loQuote.add(new Quote());
}
loQuoteLines = loQuote[0].QuoteLineItems;
loOpp = [select Account.Id, Account.Name from Opportunity where id =:loQuote[0].OpportunityId];
}
global override virtual string ShouldCalcTax()
{
if(loQuote.size() < 1)
return 'testing';
}
Try like this
global List<Quote> loQuote = null;
global virtual void Initialize()
{
loQuote = [select Id, OpportunityId,
Quote_Date__c, Pricebook2Id, Tax_Date__c, Tax_Now_Status__c, Non_Taxable__c, TotalPrice,
ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry,
BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingHandling,
(select Id, Pricebookentry.product2.ProductCode, Description, Pricebookentry.product2,
Quantity, TotalPrice, Sales_Tax_Amount__c, Rate__c, Sales_Tax_Details__c, UnitPrice from QuoteLineItems)
from Quote where id =:apCurPage];
if(0 == loQuote.size())
{
loQuote = new List<Quote>();
loQuote.add(new Quote());
}
loQuoteLines = loQuote[0].QuoteLineItems;
loOpp = [select Account.Id, Account.Name from Opportunity where id =:loQuote[0].OpportunityId];
}
global override virtual string ShouldCalcTax()
{
if(loQuote.size() < 1){
return 'testing';
}
else{
return NULL;
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
hi souvik9086,
when i write in test case like this:
if(loQuote.size() < 1)
{
return 'testing';
}
else
{
return NULL;
}
it gives me error like this:
Compile Error: Void method must not return a value at line 184 column 13
Why are you writing this in test case?
Write this in your controller.
The above mentioned code in your controller. i have modified that.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Hi, souvik9086
can you tell me how to write this in controller?
in example... i dont know how to write test case of this.
i am creating package of this and i got 69% code coverage...
so i am writing test case of remaining.. to reach 75%.....
Please tell me how to Write this in Controller...
global List<Quote> loQuote = null;
global virtual void Initialize()
{
loQuote = [select Id, OpportunityId,
Quote_Date__c, Pricebook2Id, Tax_Date__c, Tax_Now_Status__c, Non_Taxable__c, TotalPrice,
ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry,
BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingHandling,
(select Id, Pricebookentry.product2.ProductCode, Description, Pricebookentry.product2,
Quantity, TotalPrice, Sales_Tax_Amount__c, Rate__c, Sales_Tax_Details__c, UnitPrice from QuoteLineItems)
from Quote where id =:apCurPage];
if(0 == loQuote.size())
{
loQuote = new List<Quote>();
loQuote.add(new Quote());
}
loQuoteLines = loQuote[0].QuoteLineItems;
loOpp = [select Account.Id, Account.Name from Opportunity where id =:loQuote[0].OpportunityId];
}
global override virtual string ShouldCalcTax()
{
if(loQuote.size() < 1){
return 'testing';
}
else{
return NULL;
}
}
This is your controller write?? There only I enbeded
}
else{
return NULL;
}
this part. Is this not saving or causing any problem?
Thanks