Search code examples
javaspringspring-batchintegration-testing

Spring Batch Integration testing



We have several spring batch projects and we want to implement integration tests for them.

One of the projects reads from DB and writes to another DB.
The other project reads from DB and writes to a file.
The other reads from File and writes to DB.

How can we apply the end-to-end integration test to these projects?
How can we run this test in the pipeline?

Thank you.


Solution

  • How can we apply the end-to-end integration test to these projects?

    The End-To-End Testing of Batch Jobs section from the reference documentation explains that in details and with code examples. You can end-to-end test your job by:

    • creating dummy input data (either input file or database table)
    • run your job as you would do it in production
    • assert on the results (either output file or database table)

    There is a similar question/answer that I will add here for reference: Understanding JobLauncherTestUtils

    How can we run this test in the pipeline?

    The Creating a Unit Test Class section shows how to create a unit/integration test class which you can run as part of the test phase of your build pipeline.