Testing Background Processes

BatchJob classes can be tested with JUnit in two ways:

  • Extending the BatchJobTestCase class and implementing abstract methods.
  • Calling the submitBatchJob(SubmissionParameters) method in any ContextTestCase. This allows testing a mix of one or more background process and other business logic to be tested.

In both of these approaches, the normal commit and rollback logic of BatchJobs is subverted so that all updates performed by the batch process are rolled back when the test completes, either successfully or unsuccessfully. Therefore, these JUnit tests provide a safe way to test batch processes without making irreversible database updates.