committed by
Michael Minella
parent
88f1bc572a
commit
0d8cb9408e
@@ -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 <<features.adoc#features-lifecycle, here>>. 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
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user