Error testing with Spring Cloud Stream Test


April 2019


420 time


We are using spring-cloud-stream to manage messages between our applications.

We have custom bindings:

public interface InboundChannels {

  String TASKS = "domainTasksInboundChannel";
  String EVENTS = "eventsInboundChannel";

  SubscribableChannel tasks();

  SubscribableChannel events();


public interface OutboundChannels {

  String TASKS = "domainTasksOutboundChannel";
  String EVENTS = "eventsOutboundChannel";

  MessageChannel tasks();

  MessageChannel events();


There are processors that consumes tasks and generate events:

@EnableBinding({InboundChannels.class, OutboundChannels.class})
public class TasksProcessor {

  public TasksProcessor(
        UserService userService,
        @Qualifier(OutboundChannels.EVENTS) MessageChannel eventsChannel
  ) {
    this.userService = userService;
    this.eventsChannel = eventsChannel;

  @StreamListener(value = TASKS, condition = "headers['" + TYPE + "']=='" + CREATE_USER + "'")
  public void createUser(Message<User> message)  {
    final User user = message.getPayload();
            .subscribe(created -> {
                Message<User> successMessage = fromMessage(message, Events.USER_CREATED, created).build();


Now we wanted to test it using spring-cloud-stream-test-support and its amazing features:

public class TasksProcessorTest {

  private User user;

  private InboundChannels inboundChannels;

  private OutboundChannels outboundChannels;

  private MessageCollector collector;

  public void setup() {
    user = new User(BigInteger.ONE, "[email protected]");

  public void createUserTest() {
    final Message<User> msg = create(CREATE_USER, user).build();
    final Message<?> incomingEvent = collector.forChannel(;
    final String type = (String) incomingEvent.getHeaders().get(TYPE);


# Spring AMQP configuration

# Events channels

But then we get this error:

java.lang.IllegalArgumentException: Channel [eventsInboundChannel] was not bound by class

What are we doing wrong?

1 answers


In the .subscribe() you do eventsChannel.send(successMessage);, where that eventsChannel is from the OutboundChannels.EVENTS, but what you try to do in the test-case is like And it doesn't look like you really bind this channel anywhere.

I'm sure if you would use instead, that would work for you.