You need to sign in to do that
Don't have an account?
Improve Apex Code Coverage
Greetings, I currently only am able to achieve anywhere between 16-34% coverage with my current apex test class and am trying to determine ways to improve my apex class coverage.
Here is an instance of my apex class itself
APEX CLASS
public class ContactLookupControl {
public Contact contact {get;set;} // new contact to create
public List<Contact> results{get;set;} // search results
public string searchString{get;set;} // search keyword
public ContactLookupControl() {
contact = new Contact();
// get the current search string
searchString = System.currentPageReference().getParameters().get('lksrch');
runSearch();
}
// performs the keyword search
public PageReference search() {
runSearch();
return null;
}
// prepare the query and issue the search command
private void runSearch() {
// TODO prepare query string for complex serarches & prevent injections
results = performSearch(searchString);
}
// run the search and return the records found.
private List<Contact> performSearch(string searchString) {
String soql = 'select id, name from contact';
if(searchString != '' && searchString != null)
soql = soql + ' where name LIKE \'%' + searchString +'%\'';
soql = soql + ' limit 25';
System.debug(soql);
return database.query(soql);
}
// save the new contact record
public PageReference saveContact() {
insert contact;
// reset the contact
contact = new Contact();
return null;
}
// used by the visualforce page to send the link to the right dom element
public string getFormTag() {
return System.currentPageReference().getParameters().get('frm');
}
// used by the visualforce page to send the link to the right dom element for the text box
public string getTextBox() {
return System.currentPageReference().getParameters().get('txt');
}
}
Here's the test class too
TEST CLASS
@isTest
public class ContactLookupControlTest {
static testMethod void validateContactLookupControl() {
Contact c = new Contact();
c.FirstName = 'Paul';
c.LastName = 'Reid';
c.MailingStreet = '205 Hill Street';
c.MailingCity = 'Los Angeles';
c.MailingState = 'CA';
c.MailingPostalCode = '90015';
c.Email = 'testingout1@aol.com';
insert c;
}
}
Are there any additional steps I can pursue to enable it to work accordingly. Let me know and hope it helps.
Here is an instance of my apex class itself
APEX CLASS
public class ContactLookupControl {
public Contact contact {get;set;} // new contact to create
public List<Contact> results{get;set;} // search results
public string searchString{get;set;} // search keyword
public ContactLookupControl() {
contact = new Contact();
// get the current search string
searchString = System.currentPageReference().getParameters().get('lksrch');
runSearch();
}
// performs the keyword search
public PageReference search() {
runSearch();
return null;
}
// prepare the query and issue the search command
private void runSearch() {
// TODO prepare query string for complex serarches & prevent injections
results = performSearch(searchString);
}
// run the search and return the records found.
private List<Contact> performSearch(string searchString) {
String soql = 'select id, name from contact';
if(searchString != '' && searchString != null)
soql = soql + ' where name LIKE \'%' + searchString +'%\'';
soql = soql + ' limit 25';
System.debug(soql);
return database.query(soql);
}
// save the new contact record
public PageReference saveContact() {
insert contact;
// reset the contact
contact = new Contact();
return null;
}
// used by the visualforce page to send the link to the right dom element
public string getFormTag() {
return System.currentPageReference().getParameters().get('frm');
}
// used by the visualforce page to send the link to the right dom element for the text box
public string getTextBox() {
return System.currentPageReference().getParameters().get('txt');
}
}
Here's the test class too
TEST CLASS
@isTest
public class ContactLookupControlTest {
static testMethod void validateContactLookupControl() {
Contact c = new Contact();
c.FirstName = 'Paul';
c.LastName = 'Reid';
c.MailingStreet = '205 Hill Street';
c.MailingCity = 'Los Angeles';
c.MailingState = 'CA';
c.MailingPostalCode = '90015';
c.Email = 'testingout1@aol.com';
insert c;
}
}
Are there any additional steps I can pursue to enable it to work accordingly. Let me know and hope it helps.
Please check below blog for more information on test classess:-
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
Pleae mark this as solution if this will help you
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
All Answers
Please check below blog for more information on test classess:-
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
Pleae mark this as solution if this will help you
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
Then you can select best solution:;-