You need to sign in to do that
Don't have an account?
CBN
Help me to write a test class for trigger
trigger CaseUpdate on Case (before update) {
for(Case c:trigger.New){
if( Trigger.oldMap.get( c.id ).Status != Trigger.newMap.get(c.id ).Status && Trigger.newMap.get(c.id ).Status =='Working')
c.OwnerId=Userinfo.getUserID();
}
}
for(Case c:trigger.New){
if( Trigger.oldMap.get( c.id ).Status != Trigger.newMap.get(c.id ).Status && Trigger.newMap.get(c.id ).Status =='Working')
c.OwnerId=Userinfo.getUserID();
}
}
Please try below test class, Thanks,
Govindaraj.S
All Answers
Please try below test class, Thanks,
Govindaraj.S
Note, you need to test both the before and after aspects, that is to be sure the code works as expected with the Change of status.
You may want to break that into 3 x test methods to be more thorough. To ensure you test each of the criteria for your IF statement.
1 for status not working.
1 for status changed to working
1 for case updated but status not changed.
Regards
Andrew
Where are the Asserts?
The purpose of test code is to check that the code that is written is doing what it is intended to do. With no "Assertions", how do you know the code wont be broken the next time someone pushes an update? Yes, you have covered the lines of code, as in they will be "actioned" by the test class, but coverage without Assertions is useless (IMHO).
Regards
Andrew