목차

Spring Batch Test

JobReporitoryTestUtils

@Autowired
private JobRepositoryTestUtils jobRepositoryTestUtils;
 
@AfterEach
void tearDown() {
    jobRepositoryTestUtils.removeJobExecutions();
}
@Autowired
private JobRepositoryTestUtils jobRepositoryTestUtils;
 
@Autowired
private PlatformTransactionManager platformTransactionManager;
 
/**
 * {@link JobRepositoryTestUtils#removeJobExecutions()} 내부에 transaction이 없는데 ''autoCommit=false'' 설정때문에
 * 이 메소드 내부의 update 쿼리가 rollback 되는 현상이 발생해서 강제로 트랜잭션을 설정해준다.
 */
@AfterEach
void tearDown() {
    TransactionTemplate transactionTemplate = new TransactionTemplate(platformTransactionManager);
    transactionTemplate.afterPropertiesSet();
    transactionTemplate.execute(status -> {
        jobRepositoryTestUtils.removeJobExecutions();
        return null;
    });
}

참조