You need to sign in to do that
Don't have an account?
andrewskelton
Code Coverage Question
Ok, here is my issue. I have 1 class that I am trying to get into production. Just for simplicity I have only 1 method that returns a list of users. With this one class I have a the test method, and I get 31% coverage.
1. Why is it that when I add more methods code coverage goes down?
2. Why can I have my class with the 1 method and a test class completely empty and still have the same coverage as before?
3. Please explain or point me in the right direction about the code coverage.
Thanks.
can u post ur code.
//Controller class
public with sharing class ContactGridController {
//variable declaration
private ApexPages.StandardController controller {get; set;}
public List<Contact> searchResults {get;set;}
//public String selectedUser {get;set;}
public List<SelectOption> userList;
// standard controller - could also just use custom controller
public ContactGridController(ApexPages.StandardController controller) { }
public ContactGridController() { }
//get Users method and returns List of Users
private List<SelectOption> getUsers()
{
List<User> usrs = new List<User>();
try
{
if (userList == null)
{
usrs = [select id,firstname,lastname from user order by firstname, lastname ];
userList = new List<SelectOption>();
userList.add(new SelectOption('NoValue', '-Select One-'));
for (User u : usrs)
{
userList.add(new SelectOption(u.id, u.firstname + ' ' + u.lastname));
}
}
}
catch (Exception e)
{
String eMessage = 'System Message: ' + e;
System.Debug(eMessage);
ApexPages.addMessages(e);
}
return userList;
}
}
where is the test class you are talking about
Oh sorry forgot that part.
at first u need to create a test user in the test class and use his Id.
Hi,
Here is the link to "An Introduction to Apex Code Test Methods" :
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
Have a nice day !