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
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.