Skip to content

9 · Testing, automated

A workflow definition is code: it has branches, deadlines, retries and a rollback path, and every one of them deserves a test. This part tests the hotel booking you built, with the test kit (workflow-test), and ends with the project set up so that every change is checked automatically — before it can reach the engine.

The kit runs your definitions in the real engine, in memory, inside a JUnit 5 test: no server, no broker, no database. It gives a test four things a running deployment cannot:

  • mocks instead of workers — answer each task with a completion, a failure or silence;
  • a clock you move — three days pass in milliseconds;
  • assertions on the process — assertThat(booking).isCompensated().hasCompensated("rooms");
  • coverage of the flow — which steps, CHOICE branches, timeout routes and compensations the tests went through.

All the tests on these pages are in the workshop project, in src/test/java — and, written as data, in src/test/scenarios — and pass:

$ mvn verify
[INFO] Tests run: 1, Failures: 0, Errors: 0 -- in com.example.hotel.HappyPathTest
[INFO] Tests run: 2, Failures: 0, Errors: 0 -- in com.example.hotel.FailurePathsTest
[INFO] Tests run: 3, Failures: 0, Errors: 0 -- in com.example.hotel.RealHandlersTest
[INFO] Tests run: 4, Failures: 0, Errors: 0 -- in com.example.hotel.IntegrationsTest
[INFO] Tests run: 2, Failures: 0, Errors: 0 -- in com.example.hotel.TimeTest
[INFO] Tests run: 9, Failures: 0, Errors: 0 -- in com.example.hotel.ScenariosTest
[INFO] Tests run: 21, Failures: 0, Errors: 0, Skipped: 0
[INFO] EventConductor workflow coverage: steps 46/47 (97.9%), branches 5/6 (83.3%), edges 35/36 (97.2%)
[INFO] BUILD SUCCESS
PageWhat it tests
The happy pathEvery room booked, the forEach’s collected output
When things failA sold-out room: nothing undone until the guest decides; their cancel compensates; compensateAll for all-or-none
TimeA worker that never answers; an approval nobody gives for three days
Simulated integrationsThe hotel’s API, the language model and an agent — and the idempotency key actually sent
The real handlersYour Java handlers in the loop, and a mock that still wins
Automate itValidate, test, check migrations and coverage in CI with one command; test cases written as data
Debugging a failing testReading what a failing assertion prints

One dependency — it brings the engine, JUnit 5, Spring’s test support and AssertJ:

<dependency>
<groupId>io.mateu.workflow</groupId>
<artifactId>workflow-test</artifactId>
<version>${eventconductor.version}</version>
<scope>test</scope>
</dependency>

A test class is annotated @EventConductorTest and receives a WorkflowTestRuntime. It boots the engine in embedded mode with memory persistence, loads the definitions from classpath:/workflows/ — the same files the application runs — and answers every task on the calling thread, so there is nothing to wait for.

Test-only definitions go in a folder of their own, loaded with @EventConductorTest(definitions = "src/test/flows"). src/test/resources/workflows/ works too — the engine reads the workflows directory of every classpath root, main and test — but a file there with the same id as one of the application’s replaces it in every test (test output is first on the classpath), which is easy to forget. A folder of its own keeps the application’s definitions the ones under test.