Code coverage for Task Trigger

Trigger:

trigger deletetask on Task (before delete)
    {
    if(System.Trigger.IsDelete)
        {
        for (Task t : trigger.old)
            if (t.check__c == 1)
                {
                t.addError(‘Error: You cannot delete a Task when it is marked complete.’);
                }
        }         
}



Test Class:

@isTest
public class testClass
{
    static testmethod void test()
    {
        Task t = new Task(Type = ‘Email’,check__c = 0);
        insert t;
        delete t;
    }
}



Output:


Leave a Reply