+ Start a Discussion
Jeremy Johnson 51Jeremy Johnson 51 

Apex unit test for time-based workflow rule

How do you write an Apex unit test for logic that involves a time-based workflow rule? For example, a user sets a Case status = 'Completed' (soft close). Then a time-based workflow rule sets the status = 'Closed', and a beforeUpdate trigger saves the status only if all child Cases have status = 'Closed'. 
Best Answer chosen by Jeremy Johnson 51
Ravi Dutt SharmaRavi Dutt Sharma
Unit testing is basically meant to test your apex code, not configuration. You cannot really test a time based workflow through apex unit test. You can test the first part where case status is updated to Closed. Amnd then you can test the third part where the before update trigger comes into picture. Whatever action your time based workflow is performing, the same data update you need to do it in your test class so that part 3 gets tested.