You need to sign in to do that
Don't have an account?
sudh shukla
some help me to increase the code coverage of the following class:
Here is my class:
public class dependcustompicklist { public String selectcity { get; set; } public String selectcountry { get; set; } public Boolean test {get;set;} public dependcustompicklist(){ } public void testFunction(){ test = true; } public list <SelectOption> getcountry() { list <SelectOption> opt = new list <SelectOption> (); opt.add(new SelectOption ('','Select')); opt.add(new SelectOption ('India','India')); opt.add(new SelectOption ('US','US')); opt.add(new SelectOption ('UK','UK')); return opt; } public list <SelectOption> getcity() { list <SelectOption> opt1 = new list <SelectOption> (); if(selectcountry != null && test != false) { if(selectcountry == 'India') { opt1.add(new SelectOption ('','Select')); opt1.add(new SelectOption ('Kanpur','Kanpur',true)); opt1.add(new SelectOption ('Ghaziabad','Ghaziabad')); opt1.add(new SelectOption ('Noida','Noida')); } if(selectcountry == 'US') { opt1.add(new SelectOption ('','Select')); opt1.add(new SelectOption ('Washington DC','Washington DC')); opt1.add(new SelectOption ('New York','New York')); opt1.add(new SelectOption ('Los Angeles','Los Angeles')); } if(selectcountry == 'UK') { opt1.add(new SelectOption ('','Select')); opt1.add(new SelectOption ('London','London')); opt1.add(new SelectOption ('Paris','Paris')); //opt1.add(new SelectOption ('','')); } } return opt1; } }
Please find the below testclass with 90% coverage.
@isTest private class dependcustompicklistTestClass {
static testMethod void validateGetcountry() {
dependcustompicklist dep = new dependcustompicklist();
dep.getCountry();
dep.selectcountry = 'India';
dep.getcity();
dep.selectcountry = 'US';
dep.getcity();
dep.selectcountry = 'UK';
dep.getcity();
}
}
Please note that you need put some assert methods as best practices.I just created in a hurry.
Please let me know if it helps.
Thanks,
Shashi
All Answers
Please find the below testclass with 90% coverage.
@isTest private class dependcustompicklistTestClass {
static testMethod void validateGetcountry() {
dependcustompicklist dep = new dependcustompicklist();
dep.getCountry();
dep.selectcountry = 'India';
dep.getcity();
dep.selectcountry = 'US';
dep.getcity();
dep.selectcountry = 'UK';
dep.getcity();
}
}
Please note that you need put some assert methods as best practices.I just created in a hurry.
Please let me know if it helps.
Thanks,
Shashi