Update test binder documentation
Fix #867 * Switch to Spring Boot 1.4 and later configuration * Add artifact reference * Remove @DirtiesContext and autowired BinderFactory field
This commit is contained in:
committed by
Mark Pollack
parent
934e36ab09
commit
334ed57c00
@@ -1759,8 +1759,22 @@ While a scenario which using multiple instances for partitioned data processing
|
||||
== Testing
|
||||
|
||||
Spring Cloud Stream provides support for testing your microservice applications without connecting to a messaging system.
|
||||
You can do that by using the `TestSupportBinder`.
|
||||
This is useful especially for unit testing your microservices.
|
||||
You can do that by using the `TestSupportBinder` provided by the `spring-cloud-stream-test-support` library, which can be added as a test dependency to the application:
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
The `TestSupportBinder` uses the Spring Boot autoconfiguration mechanism to supersede the other binders found on the classpath.
|
||||
Therefore, when adding a binder as a dependency, make sure that the `test` scope is being used.
|
||||
====
|
||||
|
||||
The `TestSupportBinder` allows users to interact with the bound channels and inspect what messages are sent and received by the application
|
||||
|
||||
@@ -1772,18 +1786,13 @@ The following example shows how to test both input and output channels on a proc
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = ExampleTest.MyProcessor.class)
|
||||
@IntegrationTest({"server.port=-1"})
|
||||
@DirtiesContext
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class ExampleTest {
|
||||
|
||||
@Autowired
|
||||
private Processor processor;
|
||||
|
||||
@Autowired
|
||||
private BinderFactory<MessageChannel> binderFactory;
|
||||
|
||||
@Autowired
|
||||
private MessageCollector messageCollector;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user