Temporal Testing
The Temporal java SDK’s testing
package provides support for unit and functional testing of both Workflow and Activity code.
Test Workflow environment
The TestWorkflowEnvironment
class provides a runtime environment used to test a Workflow.
When running your Workflow code within the test environment, some aspects of its execution will work differently to better support testing. For example, Timers will “skip time” by firing without their normal delay, enabling you to quickly test long-running Workflows.
Test Workflow extension
The TestWorkflowExtention
class manages the Temporal test environment and workflow worker lifecycle. You’ll use this to register your Workflow Type and inject instances of TestWorkflowEnvironment
, WorkflowClient
, WorkflowOptions
, Worker
into test methods. This extension is registered with the testing framework using the @RegisterExtension
annotation from the JUnit package.
Example:
Test Activity environment
The TestActivityEnvironment
type is similar to TestWorkflowEnvironment
, but used for testing Activities.