From 15d24b370f8e3c2f3d1b3d0a8d2e72bedb0c0253 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Fri, 2 Oct 2020 23:49:21 +0200 Subject: [PATCH] Update documentation with expected configuration to use `@SpringBatchTest` Resolves #3699 --- spring-batch-docs/asciidoc/testing.adoc | 10 ++++++++++ .../batch/test/context/SpringBatchTest.java | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/spring-batch-docs/asciidoc/testing.adoc b/spring-batch-docs/asciidoc/testing.adoc index 42ee78e2a..d5e3af15c 100644 --- a/spring-batch-docs/asciidoc/testing.adoc +++ b/spring-batch-docs/asciidoc/testing.adoc @@ -34,6 +34,16 @@ Starting from v4.1, it is also possible to inject Spring Batch test utilities like the `JobLauncherTestUtils` and `JobRepositoryTestUtils` in the test context using the `@SpringBatchTest` annotation. +[NOTE] +==== +It should be noted that `JobLauncherTestUtils` requires a `Job` bean and that +`JobRepositoryTestUtils` requires a `DataSource` bean. Since `@SpringBatchTest` +registers a `JobLauncherTestUtils` and a `JobRepositoryTestUtils` in the test +context, it is expected that the test context contains a single autowire candidate +for a `Job` and a `DataSource` (either a single bean definition or one that is +annotated with `org.springframework.context.annotation.Primary`). +==== + [role="javaContent"] The following Java example shows the annotations in use: diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/context/SpringBatchTest.java b/spring-batch-test/src/main/java/org/springframework/batch/test/context/SpringBatchTest.java index a67fec4d3..74704535a 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/context/SpringBatchTest.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/context/SpringBatchTest.java @@ -116,6 +116,19 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * * } * + * + *

+ * It should be noted that {@link JobLauncherTestUtils} requires a + * {@link org.springframework.batch.core.Job} bean and that + * {@link JobRepositoryTestUtils} requires a {@link javax.sql.DataSource} bean. + * Since this annotation registers a {@link JobLauncherTestUtils} and a + * {@link JobRepositoryTestUtils} in the test context, it is expected that the + * test context contains a single autowire candidate for a + * {@link org.springframework.batch.core.Job} and a {@link javax.sql.DataSource} + * (either a single bean definition or one that is + * annotated with {@link org.springframework.context.annotation.Primary}). + *

+ * * @author Mahmoud Ben Hassine * @since 4.1 * @see JobLauncherTestUtils