function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bhaveshkjogibhaveshkjogi 

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" .

souvik9086souvik9086

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

 

bhaveshkjogibhaveshkjogi
when i am writing this test case that time it give me error that void should not returns type..
bhaveshkjogibhaveshkjogi

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';
}

souvik9086souvik9086

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

 

bhaveshkjogibhaveshkjogi

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

souvik9086souvik9086

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

bhaveshkjogibhaveshkjogi

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...

souvik9086souvik9086

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