The Temporal Java SDK provides a test framework to facilitate Workflow unit and integration testing.
The test framework provides a
TestWorkflowEnvironment class which includes an in-memory implementation
of the Temporal service that supports automatic time skipping. This allows you to
easily test long-running Workflows in seconds, without having to change your Workflow code.
You can use the provided
TestWorkflowEnvironment with a Java unit testing framework of your choice,
such as JUnit.
The following code implements unit tests for the
In cases where you do not wish to execute your actual Activity implementations during unit testing, you can use a framework such as Mockito to mock them.
The following code implements a unit test for the
HelloActivity sample which shows
how activities can be mocked:
In addition to writing unit and integration tests, debugging your Workflows is also a very valuable testing tool. You can debug your Workflow code using a debugger provided by your favorite Java IDE.
Note that when debugging your Workflow code, the Temporal Java SDK includes deadlock detection
which fails a Workflow Task in case the code blocks over a second without relinquishing
execution control. Because of this you can often encounter the
Exception while stepping through Workflow code during debugging.
To alleviate this issue, you can set the
TEMPORAL_DEBUG environment variable to true before debugging your