You need to sign in to do that
Don't have an account?
Matt Tindall
Test Coverage help please!
Hi,
I’m new to APEX classes and I’m trying to move one from my Sandbox to my Production but i keep getting the following error "Average test coverage across all Apex Classes and Triggers is 59%, at least 75% test coverage is required.” I have searched the internet and read many forums but i just can grasp how to implement a test class to increase my coverage.
Here is my code. Any help would be much appreciated!
public with sharing class SkipSearchController{ // The SOQL without the order and limit private String soql {get;set;} // The collection of Skip Companys to get public List<Skip_Supplier__c> suppliers {get;set;} // The current sort direction. Default to asc public String sortDir { get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; } set; } // Sort the data by the Postcode public String sortField { get { if (sortField == null) {sortField = 'Postcode_Prefix__c'; } return sortField; } set; } // format the soql for display on the visualforce page public String debugSoql { get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; } set; } // init the controller and display some sample data when the page loads public SkipSearchController() { soql = 'select Postcode_Prefix__c, Supplier_Name__c from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null'; runQuery(); } // toggles the sorting of query from asc<-->desc public void toggleSort() { // simply toggle the direction sortDir = sortDir.equals('asc') ? 'desc' : 'asc'; // run the query again runQuery(); } // runs the actual query public void runQuery() { try { suppliers = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'); } catch (Exception e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!')); } } // runs the search with parameters passed via Javascript public PageReference runSearch() { String Postcode = Apexpages.currentPage().getParameters().get('Postcode'); String Supplier = Apexpages.currentPage().getParameters().get('Supplier'); soql = 'select Postcode_Prefix__c, Supplier_Name__c from Skip_Supplier__c where Skip_Supplier__c.Postcode_Prefix__c != null'; if (!Postcode.equals('')) soql += ' and Postcode_Prefix__c LIKE \''+String.escapeSingleQuotes(Postcode)+'%\''; if (!Supplier.equals('')) soql += ' and Supplier_Name__c LIKE \''+String.escapeSingleQuotes(Supplier)+'%\''; // run the query again runQuery(); return null; } }
Thanks,
Matt
Matt
Have you tried to write a test class/method yet? If so, please post it so we can help.
If not, please look at this documentation: http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods