function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PriaviPriavi 

How to write test class for Task object?

How to write test class for following:

public class TaskModel extends SObjectModel{
    public TaskModel(final Task tsk) {
        super((Task)tsk);
    }
}

 
Best Answer chosen by Priavi
SubratSubrat (Salesforce Developers) 
Hello Priavi ,

For creating a Test class for task object you should keep these 3 points in mind :

1) Create test data for the Task object that will be used in the test class.
2) Create an instance of the TaskModel class using the test data.
3) Verify that the values of the properties in the TaskModel instance match the values in the test data.

Here is the test class ;
 
@isTest
private class TaskModelTest {
    
    static void testTaskModel() {
        // Create test data for Task object
        Task tsk = new Task();
        tsk.Subject = 'Test Task';
        tsk.Status = 'Not Started';
        tsk.Priority = 'Low';
        tsk.Description = 'This is a test task';
        
        // Create TaskModel instance using test data
        TaskModel taskModel = new TaskModel(tsk);
        
        // Verify that the values of properties in TaskModel instance match the test data
        System.assertEquals(tsk.Subject, taskModel.get('Subject'));
        System.assertEquals(tsk.Status, taskModel.get('Status'));
        System.assertEquals(tsk.Priority, taskModel.get('Priority'));
        System.assertEquals(tsk.Description, taskModel.get('Description'));
    }
}

If it helps please mark this as best answer.
Thank you.