Skip to content

Adapt framework for testing, make tests use single transaction and be revertible #4408

@romchellis

Description

@romchellis

It will be cool if there is an ability to revert changes produced from Spring batch job in test.
I tried to test some job or single step and found that typical Spring approach with idempotent tests using @Transactional doesn't work here. Even if transaction attributes were provided to support existing transaction and validateTransactionState is disabled.
So i would like to use it somehow like this
Expected Behavior

    @Test
    @Rollback
    @Transactional
    void Should_create_batches_for_existing_payments() throws Exception {
        testInvoiceGenerator.generateInvoicesForBatch(invoicesCount);
        var expectedCreatedBatchCount = invoicesCount / batchSize;

        var jobExecution = jobLauncherTestUtils.launchJob();
        int countPaymentBatchCount = countPaymentBatchCount();

        assertThat(jobExecution.getStatus()).isEqualTo(COMPLETED);
        assertThat(countPaymentBatchCount).isEqualTo(expectedCreatedBatchCount);
    }

Current Behavior

There is no way to revert commits made by Spring batch transaction manager, or override transaction behaviour in tests.

Context

Spring batch test

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions