How can I write unit / integration tests?

Learn how to test your Mutiny applications.

How can I write unit / integration tests?

Mutiny provides subscribers for Uni and Multi offering helpful assertion methods. You can use them to test pipelines.

Here is an example to test a Uni:

Uni<Integer> uni = Uni.createFrom().item(63);

UniAssertSubscriber<Integer> subscriber = uni


Testing a Multi pipeline is similar:

Multi<Integer> multi = Multi.createFrom().range(1, 5)
        .onItem().transform(n -> n * 10);

AssertSubscriber<Integer> subscriber = multi.subscribe().withSubscriber(AssertSubscriber.create(10));

        .assertItems(10, 20, 30, 40);

The assertions do not just focus on good outcomes, you can also test failures as in:

Multi<Object> multi = Multi.createFrom().failure(() -> new IOException("Boom"));

AssertSubscriber<Object> subscriber = multi

subscriber.assertFailedWith(IOException.class, "Boom");