You need to sign in to do that
Don't have an account?
tmbarry
Problem with a Test Class
Hello All,
I am trying to write a test class for a trigger I created.
The trigger is a simple trigger:
trigger SD_Member_No_Contact_30_Days on Task (after update) { for (Task t:System.Trigger.new) {if (t.Subject == 'Lost Contact Follow Up Call' ){ {if (t.IsClosed==True && t.status<>'No More Calls This Cycle' ){ SD_Member__c SDM = New SD_Member__c (id=t.whatid, Lost_Contact_Follow_Up__c=True); Update SDM; }}}} }
When I write the test class, I only get 60% coverage:
@isTest class TestClass_LostContact30Days { static testMethod void myUnitTest() { // TO DO: implement unit test // Create SD Member Record SD_Member__c sd = New SD_Member__c(First_Name__c = 'John', Last_Name__c = 'Smith', Ins_ID_Member__c = '123456', Ins_ID_Suscriber__c = '456789', address__c = '123 Main Stret', city__c = 'Aster', state__c = 'CT', zip__c = '06001', name = 'John Smith', Lost_Contact_Follow_Up__c =False); insert sd; // Test 1 Task o = new Task(); o.Subject = 'Lost Contact Follow Up Call'; //set the required fields o.WhatId=sd.id; o.Status='In Progress'; insert o; o.Status='Complete'; update o; }}
With the explanation of:
trigger SD_Member_No_Contact_30_Days on Task (after update) {
for (Task t:System.Trigger.new)
{if (t.Subject == 'Lost Contact Follow Up Call' ){
{if (t.IsClosed==True && t.status<>'No More Calls This Cycle' ){
SD_Member__c SDM = New SD_Member__c (id=t.whatid, Lost_Contact_Follow_Up__c=True);
Update SDM;
}}}}
}
Any ideas?
Thanks Todd B.
try this trigger and test class
trigger:
test class:
All Answers
can you briefly explain what the trigger is supposed to accomplish? thanks
Todd,
It looks like this if statement is returning false:
This indicate that most likely your test data doesn't meet both of these criteria.
Looking at your test data confirms this to be the case:
try this trigger and test class
trigger:
test class:
note i just revised the above trigger and test class. it does what your trigger did and the test coverage is 100%
Thanks Ross. That worked great.
If you have a few more minutes, could you explain what the last three lines of the test class do?
I quite sure what is happening there?
Thanks again.
there i query the database for the sd member record i inserted earlier. i want that record to have that custom field updated to true. the size of the list should be 1. after the list collection, i declare an integer variable, and assign it a value equal to the size of my list of records (again, 1). then assert that that the integer (and therefore the list) size is 1.
if i were getting paid i'd write a real test that tests whether the trigger is bulkified or not, but i'm not, so i did the bare minimum to get you test coverage.