Results 1 to 4 of 4

Thread: Transaction behaviour within Unit Testing

  1. #1
    Join Date
    May 2008
    Posts
    10

    Default Transaction behaviour within Unit Testing

    Hello!

    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. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    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. #3

    Default

    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. #4
    Join Date
    May 2008
    Posts
    10

    Thumbs up

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •