You need to sign in to do that
Don't have an account?
Test Class
Hi to All,
please write test class for this, its urgernt.
public with sharing class controlll {
public cont__c co;
public string country;
public string transactionid;
public string cardtype;
public controlllApexPages.StandardController controller)
{
pc = (cont__c)controller.getrecord();
}
public pagereference p1(){
if(pc.country__c == 'United States')
{
country ='US';
asdf3 c = new asdf3();
p.city = pc.city__c;
p.state = pc.state__c;
insert pc;
}
else
{
if(pc.country__c == 'Aus')
{
country ='AU';
asdf4 p = new asdf4();
p.city = pc.city__c;
p.state = pc.state__c;
insert pc;
}
}
pagereference p4 = page.successpay ;
p4.getParameters().put('transid', transactionid);
return p4.setredirect(true);
}
public cont__c getp(){
return pc;
}
Have you read the documentation or and introduction to apex testing ?
Your test method:
Did you look at the test result, and the line that got covered ? That gives you a good identitfication of how your test method should look like (in the test results, scroll down to the class and click the "coverage%").
Your test runs with a obj.Country = 'India', but your logic is based around 'US' and 'Aus', run it once with an object having country 'US' and once with country = 'Aus' for full coverage of the method.
Test all methods, by running them all in your test test method, and run them as many different times as you have possible paths of execution within your method itself. Making sure every path of execution will be tested.
Hi,
public with sharing class controlll {
public cont__c co;
public string country;
public string transactionid;
public string cardtype;
public controlllApexPages.StandardController controller)
{
pc = (cont__c)controller.getrecord();
}
public pagereference p1(){
if(pc.country__c == 'United States')
{
country ='US';
asdf3 c = new asdf3();
p.city = pc.city__c;
p.state = pc.state__c;
insert pc;
}
else
{
if(pc.country__c == 'Aus')
{
country ='AU';
asdf4 p = new asdf4();
p.city = pc.city__c;
p.state = pc.state__c;
insert pc;
}
}
pagereference p4 = page.successpay ;
p4.getParameters().put('transid', transactionid);
return p4.setredirect(true);
}
public cont__c getp(){
return pc;
}
these lines are not covered in the test coverage, asam new for writing testcalsses, please hepl hoe to write test class for this.
i change the country value to US and Aus, but no change in the code coverage,
Thanks
Yes ... you're setting the controller country in your rest. The country that needs to change is the country of the record your controller is based around. a cont__c object, its that country field that needs to change.
You're testing a controller extention, which relies on the controller, this implies you also need to include that in your test code. Have a look at the following code snippet as referende
Please read and study (= understand) those links I posted.