Skip to main content

Unit Testing framework for workflows

The framework allows you to test the workflow definitions against a specific version of Conductor server.

The unit tests allows the following:

  1. Input/Output Wiring: Ensure the tasks are wired up correctly
  2. Parameter check: Workflow behavior with missing mandatory parameters is expected (fail if required)
  3. Task Failure behavior: Ensure the task definitions have right no. of retries etc.
    e.g. If the task is not idempotent, it does not get retried.
  4. Branch Testing: Given a specific input, ensure the workflow executes specific branch of the fork/decision.

The local test server is self-contained with no additional dependencies required and stores all the data in memory. Once the tests complete, the server is terminated and all the data is wiped out.

Unit Testing frameworks

The testing framework is agnostic to the framework you use for testing, can be easily integrated into JUnit, Spock and other testing framework being used.

Setting up the local server for testing

//Setup method  code - should be called once per the test lifecycle
//e.g. @BeforeClass in JUnit

//Download the published conductor server version 3.5.2
//Start the local server at port 8096
testRunner = new WorkflowTestRunner(8096, "3.5.2");

//Scan the packages for task workers

//Get the executor instance used for loading workflows
executor = testRunner.getWorkflowExecutor();

Clean up method

//Clean up method code -- place in a clean up method e.g. @AfterClass in Junit

//Shutdown local workers and server and clean up any local resources in use.

Loading workflows from JSON files for testing


Sample test code that starts a workflow and verifies its execution

GetInsuranceQuote getQuote = new GetInsuranceQuote();

// Start the workflow and wait for it to complete
CompletableFuture<Workflow> workflowFuture = executor.executeWorkflow("InsuranceQuoteWorkflow", 1, getQuote);

//Wait for the workflow execution to complete
Workflow workflow = workflowFuture.get();

assertEquals(Workflow.WorkflowStatus.COMPLETED, workflow.getStatus());
assertTrue(workflow.getTasks().stream().anyMatch(task -> task.getTaskDefName().equals("task_6")));