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 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_enabled=false"})
public class DemoApplicationTests {

	@Test
	public void contextLoads() {
	//your test here
	}

}