{"id":25237,"date":"2026-06-03T06:20:35","date_gmt":"2026-06-02T23:20:35","guid":{"rendered":"https:\/\/huongdanjava.com\/?p=25237"},"modified":"2026-06-03T06:20:35","modified_gmt":"2026-06-02T23:20:35","slug":"unit-testing-with-spring-cloud-stream","status":"publish","type":"post","link":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html","title":{"rendered":"Unit testing with Spring Cloud Stream"},"content":{"rendered":"<p>Spring Cloud Stream provides the `spring-cloud-stream-test-binder` dependency, allowing us to easily write unit tests for applications using Spring Cloud Stream without having to call actual message brokers.<\/p>\n<p>You can declare and use this `spring-cloud-stream-test-binder` dependency as follows:<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;dependency&gt;\r\n  &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\r\n  &lt;artifactId&gt;spring-cloud-stream-test-binder&lt;\/artifactId&gt;\r\n  &lt;scope&gt;test&lt;\/scope&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>I&#8217;ll use the example project from <a href=\"https:\/\/huongdanjava.com\/send-messages-using-spring-cloud-streams-streambridge.html\" target=\"_blank\" rel=\"noopener\">the previous tutorial<\/a> as an illustration!<\/p>\n<p>To write unit tests for Spring Cloud Stream, we&#8217;ll annotate the test class with the annotation @EnableTestBinder:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springcloudstream;\r\n\r\nimport org.springframework.boot.test.context.SpringBootTest;\r\nimport org.springframework.cloud.stream.binder.test.EnableTestBinder;\r\n\r\n@SpringBootTest\r\n@EnableTestBinder\r\nclass SpringCloudStreamRabbitmqExampleApplicationTests {\r\n\r\n}\r\n<\/pre>\n<p>The @EnableTestBinder annotation will prompt Spring to create two beans, InputDestination and OutputDestination, allowing us to simulate sending and receiving messages to a message broker with Spring Cloud Stream. InputDestination will simulate receiving messages from the message broker to the application, while OutputDestination will simulate sending messages from the application to the message broker.<\/p>\n<p>I will create a new application.yml file in the src\/test\/resources directory to use for this testing!<\/p>\n<h3>InputDestination<\/h3>\n<p>As I mentioned above, the bean of the InputDestination class will simulate receiving messages from a message broker to the application.<\/p>\n<p>Currently, in the example project, I have defined a bean of the Consumer interface to receive messages from the message broker:<\/p>\n<pre class=\"lang:java decode:true \">@Bean\r\npublic Consumer&lt;String&gt; receiveConsumer() {\r\n  return message -&gt; {\r\n    System.out.println(\"Received: \" + message);\r\n  };\r\n}<\/pre>\n<p>For testing, to illustrate the assertion, I will add a new class MessageStore with the annotation @Component:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springcloudstream;\r\n\r\nimport org.springframework.stereotype.Component;\r\n\r\n@Component\r\npublic class MessageStore {\r\n\r\n  private String lastMessage;\r\n\r\n  public void setLastMessage(String message) {\r\n    this.lastMessage = message;\r\n  }\r\n\r\n  public String getLastMessage() {\r\n    return lastMessage;\r\n  }\r\n}<\/pre>\n<p>So that when it receives a message from the message broker, this MessageStore class will record that message as follows:<\/p>\n<pre class=\"lang:java decode:true \">@Bean\r\npublic Consumer&lt;String&gt; receiveConsumer(MessageStore store) {\r\n  return message -&gt; {\r\n    store.setLastMessage(message);\r\n    System.out.println(\"Received: \" + message);\r\n  };\r\n}<\/pre>\n<p>I will define the binding for the Consumer interface in the application.yml file in the src\/test\/resources directory as follows:<\/p>\n<pre class=\"lang:yaml decode:true \">spring:\r\n  cloud:\r\n    stream:\r\n      bindings:\r\n        receiveConsumer-in-0:\r\n          destination: message.exchange\r\n          group: huongdanjava\r\n<\/pre>\n<p>In the unit test, we will ingest the bean of the InputDestination class, send a message to the destination, and assert the result as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springcloudstream;\r\n\r\nimport static org.junit.jupiter.api.Assertions.assertEquals;\r\n\r\nimport org.junit.jupiter.api.Test;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\n\r\nimport org.springframework.boot.test.context.SpringBootTest;\r\nimport org.springframework.cloud.stream.binder.test.EnableTestBinder;\r\nimport org.springframework.cloud.stream.binder.test.InputDestination;\r\nimport org.springframework.messaging.support.MessageBuilder;\r\n\r\n@SpringBootTest\r\n@EnableTestBinder\r\nclass SpringCloudStreamRabbitmqExampleApplicationTests {\r\n\r\n  @Autowired\r\n  private InputDestination inputDestination;\r\n\r\n  @Autowired\r\n  private MessageStore store;\r\n\r\n  @Test\r\n  void testInputDestination() {\r\n    String testMessage = \"Test Message\";\r\n    var message = MessageBuilder.withPayload(testMessage)\r\n        .build();\r\n\r\n    inputDestination.send(message, \"message.exchange\");\r\n\r\n    assertEquals(testMessage, store.getLastMessage());\r\n  }\r\n\r\n}\r\n<\/pre>\n<p>The `send()` method of the `InputDestination` class has two parameters. The first parameter is the message we want to send, and the second parameter is the name of the Exchange in RabbitMQ or the name of the Topic in Apache Kafka that the application will receive the message from. This `InputDestination` class also has several other `send()` methods, but I recommend using the `send()` method with two parameters as shown above, so that the test can work in any case.<\/p>\n<p>Run this test, and you will see the following pass result:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25239 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/06\/unit-testing-with-spring-cloud-stream-1.png\" alt=\"\" width=\"700\" height=\"405\" \/><\/p>\n<h3>OutputDestination<\/h3>\n<p>The OutputDestination class will simulate sending messages from the application to the message broker.<\/p>\n<p>For example, you can define a bean of the Supplier interface as I did in <a href=\"https:\/\/huongdanjava.com\/introduction-to-spring-cloud-stream.html\" target=\"_blank\" rel=\"noopener\">the previous tutorial<\/a>:<\/p>\n<pre class=\"lang:java decode:true \">@Bean\r\npublic Supplier&lt;String&gt; sendSupplier() {\r\n  return () -&gt; \"Hello World\";\r\n}<\/pre>\n<p>\u0110\u1ecbnh ngh\u0129a binding cho n\u00f3:<\/p>\n<pre class=\"lang:yaml decode:true \">spring:\r\n  cloud:\r\n    function:\r\n      definition: receiveConsumer;sendSupplier\r\n    stream:\r\n      bindings:\r\n        receiveConsumer-in-0:\r\n          destination: message.exchange\r\n          group: huongdanjava\r\n        sendSupplier-out-0:\r\n          destination: message.exchange\r\n<\/pre>\n<p>And you can write tests using the OutputDestination class as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springcloudstream;\r\n\r\nimport static org.junit.jupiter.api.Assertions.assertEquals;\r\nimport static org.junit.jupiter.api.Assertions.assertNotNull;\r\nimport static org.junit.jupiter.api.Assertions.assertTrue;\r\n\r\nimport org.junit.jupiter.api.Test;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.boot.test.context.SpringBootTest;\r\nimport org.springframework.cloud.stream.binder.test.EnableTestBinder;\r\nimport org.springframework.cloud.stream.binder.test.InputDestination;\r\nimport org.springframework.cloud.stream.binder.test.OutputDestination;\r\nimport org.springframework.messaging.support.MessageBuilder;\r\n\r\n@SpringBootTest\r\n@EnableTestBinder\r\nclass SpringCloudStreamRabbitmqExampleApplicationTests {\r\n\r\n  @Autowired\r\n  private InputDestination inputDestination;\r\n\r\n  @Autowired\r\n  private OutputDestination outputDestination;\r\n\r\n  @Autowired\r\n  private MessageStore store;\r\n\r\n  @Test\r\n  void testInputDestination() {\r\n    String testMessage = \"Test Message\";\r\n    var message = MessageBuilder.withPayload(testMessage)\r\n        .build();\r\n\r\n    inputDestination.send(message, \"message.exchange\");\r\n\r\n    assertEquals(testMessage, store.getLastMessage());\r\n  }\r\n\r\n  @Test\r\n  void testOutputDestination() {\r\n    var response = outputDestination.receive(100, \"message.exchange\");\r\n    assertNotNull(response);\r\n    assertTrue(response.getPayload().length &gt; 0);\r\n\r\n    assertEquals(\"Hello World\", new String(response.getPayload()));\r\n  }\r\n\r\n}\r\n<\/pre>\n<p>The `receive()` method of the `OutputDestination` class has two parameters: a timeout and the name of the Exchange or Topic that will receive the message. Similar to the `InputDestination` class, the `OutputDestination` class also has several other `receive()` methods, but I recommend using the `receive()` method with two parameters as shown above, so that the test can work in any case.<\/p>\n<p>The results of running this test will be as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25240 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/06\/unit-testing-with-spring-cloud-stream-2.png\" alt=\"\" width=\"700\" height=\"448\" \/><\/p>\n<p>So, in this tutorial, I&#8217;ve shown you how to use the InputDestination and OutputDestination classes to write unit tests in applications using Spring Cloud Stream. Not having to call the external message broker when running unit tests will be very helpful!<\/p>\n<p><strong>You can watch the video here:<\/strong><\/p>\n<p><iframe loading=\"lazy\" title=\"Spring Cloud Stream Unit Testing with Test Binder | InputDestination &amp; OutputDestination Tutorial\" width=\"825\" height=\"619\" src=\"https:\/\/www.youtube.com\/embed\/ftl6CtOs39c?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-right kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;right&quot;,&quot;id&quot;:&quot;25237&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;4&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Unit testing with Spring Cloud Stream&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\"><\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring Cloud Stream provides the `spring-cloud-stream-test-binder` dependency, allowing us to easily write unit tests for applications using Spring Cloud Stream without having to call actual message brokers. You can declare and use this `spring-cloud-stream-test-binder` dependency as follows: &lt;dependency&gt; &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt; &lt;artifactId&gt;spring-cloud-stream-test-binder&lt;\/artifactId&gt; &lt;scope&gt;test&lt;\/scope&gt; &lt;\/dependency&gt; I&#8217;ll use the&hellip; <a href=\"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":25085,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2553],"tags":[],"class_list":["post-25237","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-cloud-stream-en","clearfix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Unit testing with Spring Cloud Stream - Huong Dan Java<\/title>\n<meta name=\"description\" content=\"In this tutorial, I guide you all on how to write unit tests with Spring Cloud Stream using Test Binder.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unit testing with Spring Cloud Stream - Huong Dan Java\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I guide you all on how to write unit tests with Spring Cloud Stream using Test Binder.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html\" \/>\n<meta property=\"og:site_name\" content=\"Huong Dan Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-02T23:20:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/04\/spring-cloud.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Khanh Nguyen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/KhanhNguyenJ\" \/>\n<meta name=\"twitter:site\" content=\"@KhanhNguyenJ\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khanh Nguyen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html\"},\"author\":{\"name\":\"Khanh Nguyen\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"headline\":\"Unit testing with Spring Cloud Stream\",\"datePublished\":\"2026-06-02T23:20:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html\"},\"wordCount\":538,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/spring-cloud.jpg\",\"articleSection\":[\"Spring Cloud Stream\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html\",\"name\":\"Unit testing with Spring Cloud Stream - Huong Dan Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/spring-cloud.jpg\",\"datePublished\":\"2026-06-02T23:20:35+00:00\",\"description\":\"In this tutorial, I guide you all on how to write unit tests with Spring Cloud Stream using Test Binder.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#primaryimage\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/spring-cloud.jpg\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/spring-cloud.jpg\",\"width\":400,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/unit-testing-with-spring-cloud-stream.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/huongdanjava.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unit testing with Spring Cloud Stream\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/\",\"name\":\"Huong Dan Java\",\"description\":\"Java development tutorials\",\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/huongdanjava.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\",\"name\":\"Khanh Nguyen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"width\":1267,\"height\":1517,\"caption\":\"Khanh Nguyen\"},\"logo\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\"},\"description\":\"I love Java and everything related to Java.\",\"sameAs\":[\"https:\\\/\\\/huongdanjava.com\",\"https:\\\/\\\/www.facebook.com\\\/nhkhanh2406\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/KhanhNguyenJ\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unit testing with Spring Cloud Stream - Huong Dan Java","description":"In this tutorial, I guide you all on how to write unit tests with Spring Cloud Stream using Test Binder.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html","og_locale":"en_US","og_type":"article","og_title":"Unit testing with Spring Cloud Stream - Huong Dan Java","og_description":"In this tutorial, I guide you all on how to write unit tests with Spring Cloud Stream using Test Binder.","og_url":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html","og_site_name":"Huong Dan Java","article_publisher":"https:\/\/www.facebook.com\/nhkhanh2406","article_author":"https:\/\/www.facebook.com\/nhkhanh2406","article_published_time":"2026-06-02T23:20:35+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/04\/spring-cloud.jpg","type":"image\/jpeg"}],"author":"Khanh Nguyen","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/KhanhNguyenJ","twitter_site":"@KhanhNguyenJ","twitter_misc":{"Written by":"Khanh Nguyen","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#article","isPartOf":{"@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html"},"author":{"name":"Khanh Nguyen","@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"headline":"Unit testing with Spring Cloud Stream","datePublished":"2026-06-02T23:20:35+00:00","mainEntityOfPage":{"@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html"},"wordCount":538,"commentCount":0,"publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"image":{"@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/04\/spring-cloud.jpg","articleSection":["Spring Cloud Stream"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html","url":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html","name":"Unit testing with Spring Cloud Stream - Huong Dan Java","isPartOf":{"@id":"https:\/\/huongdanjava.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#primaryimage"},"image":{"@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/04\/spring-cloud.jpg","datePublished":"2026-06-02T23:20:35+00:00","description":"In this tutorial, I guide you all on how to write unit tests with Spring Cloud Stream using Test Binder.","breadcrumb":{"@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#primaryimage","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/04\/spring-cloud.jpg","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2026\/04\/spring-cloud.jpg","width":400,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/huongdanjava.com\/unit-testing-with-spring-cloud-stream.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/huongdanjava.com\/"},{"@type":"ListItem","position":2,"name":"Unit testing with Spring Cloud Stream"}]},{"@type":"WebSite","@id":"https:\/\/huongdanjava.com\/#website","url":"https:\/\/huongdanjava.com\/","name":"Huong Dan Java","description":"Java development tutorials","publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/huongdanjava.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d","name":"Khanh Nguyen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","width":1267,"height":1517,"caption":"Khanh Nguyen"},"logo":{"@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg"},"description":"I love Java and everything related to Java.","sameAs":["https:\/\/huongdanjava.com","https:\/\/www.facebook.com\/nhkhanh2406","https:\/\/x.com\/https:\/\/twitter.com\/KhanhNguyenJ"]}]}},"_links":{"self":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/25237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/comments?post=25237"}],"version-history":[{"count":2,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/25237\/revisions"}],"predecessor-version":[{"id":25241,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/25237\/revisions\/25241"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media\/25085"}],"wp:attachment":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media?parent=25237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/categories?post=25237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/tags?post=25237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}