2017-02-11 48 views
1

Мне нужно увеличить покрытие кода на моем тестовом примере. Сейчас я около 50%. Я знаю, что мое расширение - это учетная запись, но мне нужно как-то включить информацию о задаче и Account.ParentId! = Null и Task.Status =: «Завершена» в мой тестовый пример ... Любая помощь будет оценена ...Увеличьте покрытие кода на стандартном тестовом примере разработчика Salesforce

Мой контроллер:

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

ко второму @EricSSH - вы должны сделать тесты на самом деле проходят через весь код, создав некоторые данные. Следующий трейлин был очень полезен для меня с тестированием Apex.

https://trailhead.salesforce.com/modules/apex_testing