Announcement Announcement Module
No announcement yet.
Transaction behaviour within Unit Testing Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction behaviour within Unit Testing


    after having read the reference docs and doing some testing by myself I am kind of lost concerning the transaction behaviour of Spring Batch within Junit tests.

    Obviously, with Spring Batch setting of commit or rollback commands within the chunks we are not able to rollback when ending the unit tests. In order to execute tests not only once I would prefer to "leave nothing but footprints" after a suite run. Cleaning up by using @After annotation seems to be risky, since failing appropriate maintaining of the sweeper code may result in creating inconsistencies.

    Therefore I would be great if you could provide some "patterns" dealing with Spring Batch and Junit Tests.

    Thanks in advance!

  • #2
    I tend to clean the whole database and inject test data before each test method (for any kind of test, Spring Batch or not.) This can look brutal, but it works nicely. Cleaning doesn't take that long (10s ms, depending on the number of tables and the database.)


    • #3
      Unless you don't rely on the fact that an existing job instance already existed or something like that, it's job specific I'd say.

      If your job touches some business tables when it runs, you know about them in your test so I would create the necessary helpers to clean that just as you would build helper (or matcher) to assert that the job ran successfully.


      • #4
        Dear all,

        thank you for your replies. According to your suggestions, I now clean the database before an after executing tests.

        Anyway: I am looking forward receiving addtional ideas.

        Kind regards