diff --git a/spring-cloud-task-docs/src/main/asciidoc/getting-started.adoc b/spring-cloud-task-docs/src/main/asciidoc/getting-started.adoc index 90041d07..ba845bfd 100755 --- a/spring-cloud-task-docs/src/main/asciidoc/getting-started.adoc +++ b/spring-cloud-task-docs/src/main/asciidoc/getting-started.adoc @@ -292,3 +292,26 @@ of the Spring Cloud Task Project https://github.com/spring-cloud/spring-cloud-task/tree/master/spring-cloud-task-samples/timestamp[here]. +=== Writing your test + +When writing your unit tests for a Spring Cloud Task application we have to keep +in mind that Spring Cloud Task closes the context at the completion of the task +as discussed <>. If you are using Spring +Framework's testing functionality to manage the application context, you'll want to turn +off Spring Cloud Task's auto-closing of the context. Add the following +line: `@TestPropertySource(properties = {"spring.cloud.task.closecontext_enable=false"})` +to your tests will keep the context open. For example: + +``` +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(properties = {"spring.cloud.task.closecontext_enable=false"}) +public class DemoApplicationTests { + + @Test + public void contextLoads() { + //your test here + } + +} +``` \ No newline at end of file