The class AbstractTransactionalJUnit4SpringContextTests contains a protected field jdbcTemplate of type JdbcTemplate.

This field assists in writing tests which inherit from AbstractTransactionalJUnit4SpringContextTests.

I suggest to also add a jdbcClient field of type JdbClient.

Then we can use this field in our tests.

Comment From: sbrannen

Hi @hansdesmet,

Thanks for the proposal.

To be honest, we have been considering deprecating both AbstractJUnit4SpringContextTests and AbstractTransactionalJUnit4SpringContextTests for quite some time.

AbstractJUnit4SpringContextTests in particular has practically no added value since Spring Framework 6.0, since it no longer registers TestExecutionListeners (see #29149) and since it's extremely easy to declare @Autowired ApplicationContext applicationContext; if you ever need access to the application context.

Similarly, AbstractTransactionalJUnit4SpringContextTests does not provide much added value since most of its convenience methods only delegate to JdbcTestUtils. Plus, many of its other features can be achieved via @Sql or other means.

In light of that, we do not have any plans to extend the feature set of those JUnit 4 base classes.

Out of curiosity, what is the concrete use case you have for relying on AbstractTransactionalJUnit4SpringContextTests.

Regards,

Sam


As a side note, if you're set on using AbstractTransactionalJUnit4SpringContextTests, it's relatively easy to create a JdbcClient via JdbcClient.create(this.jdbcTemplate).

Comment From: hansdesmet

Hi Sam,

I can indeed omit AbstractTransactionalJUnit4SpringContextTests from my code and use JdbcTestUtils instead.

But the methods of JdbcTestUtils expect a JdbcTemplate parameter.

I would like my code to use only JdbcClient, not JdbcTemplate.

Regards

Hans

Comment From: sbrannen

Thanks for the feedback, @hansdesmet! 👍

As a result, I've created the following issues.

  • 31065

  • 31066