我需要增加测试用例的代码覆盖率。现在,我大约50%。我知道我的扩展名是Account,但我不知何故需要在我的测试用例中包含任务信息和Account.ParentId!= Null和Task.Status =:'已完成'...任何帮助将不胜感激......
我的控制器:
public class childTaskOnParentCont {
public Account acc {get;set;}
public List<Task> tasks {get;set;}
public List<Task> closedTasks {get;set;}
public List<Task> tasksLimited {get;set;}
public List<Task> closedTasksLimited {get;set;}
public List<Contact> cons {get;set;}
//constructor
public childTaskOnParentCont(apexpages.StandardController con){
acc = (Account) con.getRecord();
cons=[SELECT id from Contact WHERE AccountID=: acc.Id];
tasksLimited= [Select whoid,whatid,subject,type, Medium_of_Activity__c, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status !='completed' ORDER BY activitydate LIMIT 10];
system.debug('taskslimited: '+taskslimited);
closedTasksLimited= [Select whoid,subject,type, Medium_of_Activity__c, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status =:'completed' ORDER BY activitydate LIMIT 10];
system.debug('closedTasksLimited: '+closedTasksLimited);
}
//Get the Account Information
public Account getAccount() {
return [SELECT id,ParentId, name FROM Account WHERE Id=: acc.Id];
}
//Get Open Tasks for Child Tasks
public List<Task> getTasks() {
tasks= [Select whoid,subject,type, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status !='completed' ORDER BY activitydate];
return tasks;
}
//Get Closed Tasks for Child Tasks
public List<Task> getClosedTasks() {
closedTasks= [Select whoid,subject,type, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status =:'completed' ORDER BY activitydate];
return closedTasks;
}
}
My Test Case:
public class childTaskOnParentCont {
public Account acc {get;set;}
public List<Task> tasks {get;set;}
public List<Task> closedTasks {get;set;}
public List<Task> tasksLimited {get;set;}
public List<Task> closedTasksLimited {get;set;}
public List<Contact> cons {get;set;}
//constructor
public childTaskOnParentCont(apexpages.StandardController con){
acc = (Account) con.getRecord();
cons=[SELECT id from Contact WHERE AccountID=: acc.Id];
tasksLimited= [Select whoid,whatid,subject,type, Medium_of_Activity__c, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status !='completed' ORDER BY activitydate LIMIT 10];
system.debug('taskslimited: '+taskslimited);
closedTasksLimited= [Select whoid,subject,type, Medium_of_Activity__c, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status =:'completed' ORDER BY activitydate LIMIT 10];
system.debug('closedTasksLimited: '+closedTasksLimited);
}
//Get the Account Information
public Account getAccount() {
return [SELECT id,ParentId, name FROM Account WHERE Id=: acc.Id];
}
//Get Open Tasks for Child Tasks
public List<Task> getTasks() {
tasks= [Select whoid,subject,type, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status !='completed' ORDER BY activitydate];
return tasks;
}
//Get Closed Tasks for Child Tasks
public List<Task> getClosedTasks() {
closedTasks= [Select whoid,subject,type, activitydate, lastmodifieddate,Account.Name,
ownerid, status, priority from Task
Where Account.ParentID != null And status =:'completed' ORDER BY activitydate];
return closedTasks;
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
要获得第二个@EricSSH - 您必须通过创建一些数据来使测试实际运行整个代码。通过Apex测试,以下开端对我非常有帮助。