2

I have a spring boot spring batch project. The following setting is in my application.yml

# Spring Framework Standard Properties
spring:
  batch:
    job.enabled: true

When I have this setting set to true as above it causes my junit tests to run twice everytime I kick off a unit test.

When I change the setting to false my junit tests run once when I kick off the same unit test.

A couple of questions...

I am not 100% clear on what this setting is. Can someone tell me more.

And also is there anything I can put in my unit test to change this to false just for my unit tests.

Richie
  • 4,989
  • 24
  • 90
  • 177

1 Answers1

5

From the official documentation:

By default a Runner will be created and all jobs in the context will be executed on startup.

Disable this behavior with spring.batch.job.enabled=false.

Community
  • 1
  • 1
Miloš Milivojević
  • 5,219
  • 3
  • 26
  • 39
  • Thank you! Is there something I can put in the unit test ( like setting this via an annotation) to override what is in the application.yml file? – Richie Jul 22 '16 at 13:14
  • You can create application-test.yml in `src/test/resources` and put it in there and just annotate your class with `@ActiveProfiles("test")`. Or just annotate your class with `@IntegrationTest("spring.batch.job.enabled=false")`, it will override the property for that test. – Miloš Milivojević Jul 22 '16 at 14:32
  • @IntegrationTest("spring.batch.job.enabled=false") worked!. This is the solution that suits me better bc I don't want to have to redefine everything that is in my other application.yml file. – Richie Jul 24 '16 at 10:13
  • Actually, you would just have to put the overrides into application-test file. But yeah, either should work so whatever fits better for your use case. – Miloš Milivojević Jul 24 '16 at 11:14