Class ProcessEngineRule

  • All Implemented Interfaces:
    ProcessEngineServices, org.junit.rules.TestRule
    Direct Known Subclasses:

    public class ProcessEngineRule
    extends org.junit.rules.TestWatcher
    implements ProcessEngineServices
    Convenience for ProcessEngine and services initialization in the form of a JUnit rule.


     public class YourTest {
       public ProcessEngineRule processEngineRule = new ProcessEngineRule();

    The ProcessEngine and the services will be made available to the test class through the getters of the processEngineRule. The processEngine will be initialized by default with the camunda.cfg.xml resource on the classpath. To specify a different configuration file, pass the resource location in the appropriate constructor. Process engines will be cached statically. Right before the first time the setUp is called for a given configuration resource, the process engine will be constructed.

    You can declare a deployment with the Deployment annotation. This base class will make sure that this deployment gets deployed before the setUp and cascade deleted after the tearDown. If you add a deployment programmatically in your test, you have to make it known to the processEngineRule by calling manageDeployment(org.camunda.bpm.engine.repository.Deployment) to have it cleaned up automatically.

    The processEngineRule also lets you set the current time used by the process engine. This can be handy to control the exact time that is used by the engine in order to verify e.g., due dates of timers. Or start, end and duration times in the history service. In the tearDown, the internal clock will automatically be reset to use the current system time rather then the time that was set during a test method. In other words, you don't have to clean up your own time messing mess ;-)

    If you need the history service for your tests then you can specify the required history level of the test method or class, using the RequiredHistoryLevel annotation. If the current history level of the process engine is lower than the specified one then the test is skipped.

    Tom Baeyens