You need to sign in to do that
Don't have an account?
Help required in writing test class
public class Activity
public class Activity {Task Task;public Activity(ApexPages.StandardController controller) { }List<Task> tsk = new List<Task>();public List<Task> getactivit() { tsk = [select Subject, Assign_To__c,Status, ActivityDate, Description, Action_Item__c from Task where WhatId =:ApexPages.CurrentPage().getParameters().get('id')]; return tsk;
}
}
-----------------------------------------------------------------------------------------------
Can anyone help me out with the test class, and should the test class be along with the above code.
Appreciate your help
Add the highlighted test method in your class:
public class Activity {
public Activity(ApexPages.StandardController controller){
}
List<Task> tsk = new List<Task>();
public List<Task> getactivit()
{
tsk = [select Subject, Assign_To__c,Status, ActivityDate, Description, Action_Item__c from Task
where WhatId =:ApexPages.CurrentPage().getParameters().get('id')];
return tsk;
}
public static testmethod void testActivityClass(){
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Send Out Notice To Vacate';
t.Status='Not Started';
t.Priority='Normal';
t.Assign_To__c=NULL;
t.Action_Item__c=NULL;
insert t;
ApexPages.StandardController con = new ApexPages.StandardController(t);
Activity a = new Activity(con);
List<Task> tsk = a.getactivit();
}
}
* You can also add this method in a separate class as follows
@isTest
private class testActivityclass{
static testmethod void testActivity(){
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Send Out Notice To Vacate';
t.Status='Not Started';
t.Priority='Normal';
t.Assign_To__c=NULL;
t.Action_Item__c=NULL;
insert t;
ApexPages.StandardController con = new ApexPages.StandardController(t);
Activity a = new Activity(con);
List<Task> tsk = a.getactivit();
}
}
You can refer to the following link for writing test class
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
Let me know if you face any difficulty..........
Hope this helps you.
All Answers
Add the highlighted test method in your class:
public class Activity {
public Activity(ApexPages.StandardController controller){
}
List<Task> tsk = new List<Task>();
public List<Task> getactivit()
{
tsk = [select Subject, Assign_To__c,Status, ActivityDate, Description, Action_Item__c from Task
where WhatId =:ApexPages.CurrentPage().getParameters().get('id')];
return tsk;
}
public static testmethod void testActivityClass(){
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Send Out Notice To Vacate';
t.Status='Not Started';
t.Priority='Normal';
t.Assign_To__c=NULL;
t.Action_Item__c=NULL;
insert t;
ApexPages.StandardController con = new ApexPages.StandardController(t);
Activity a = new Activity(con);
List<Task> tsk = a.getactivit();
}
}
* You can also add this method in a separate class as follows
@isTest
private class testActivityclass{
static testmethod void testActivity(){
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Send Out Notice To Vacate';
t.Status='Not Started';
t.Priority='Normal';
t.Assign_To__c=NULL;
t.Action_Item__c=NULL;
insert t;
ApexPages.StandardController con = new ApexPages.StandardController(t);
Activity a = new Activity(con);
List<Task> tsk = a.getactivit();
}
}
You can refer to the following link for writing test class
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
Let me know if you face any difficulty..........
Hope this helps you.
Perfect thanks.
Appreciate your help