Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc/feat Transaction Template tests #40033

Closed
xenoterracide opened this issue Mar 20, 2024 · 1 comment
Closed

Doc/feat Transaction Template tests #40033

xenoterracide opened this issue Mar 20, 2024 · 1 comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@xenoterracide
Copy link
Contributor

xenoterracide commented Mar 20, 2024

So recently I had problems testing something that would have been easy to do with TransactionTemplate, that something was envers and it's documented in the spring data envers docs, which I didn't completely read, and that's my fault. However, doing this with spring boot is a little different because it can set the test up for you. However, it's perhaps not as streamlined as DataJpaTest. This is what came up with

@SpringBootTest
@AutoConfigureDataJpa
@AutoConfigureTestDatabase
public class JpaAggregateTest {

  @Autowired
  TransactionTemplate tx;
  
  @Autowired
  FooAggregateRepository repository;

I'm not even sure if that's all necessary, but it works.

However I was thinking at minimum it might be nice to document in the reference docs. The javadoc for @AutoconfigureDataJpa also suggests I shouldn't be using it, it might be better to update that to "when" I should be using it.

I'm thinking that it might be convenient to add @DataTransactionTemplateTest and @JdbcTransactionTemplateTest, but that might be overkill when documentation would suffice. However, if those were to exist they could possibly go the next mile and set up a different h2 database that would get destroyed either at the end of the test or at least after class, instead of perpetuating for the whole suite (which I believe it does now).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 20, 2024
@philwebb
Copy link
Member

Thanks for the suggestion, but I think it might be hard for us to describe this scenario in the @AutoconfigureDataJpa javadoc.

The "Most tests should consider using ... rather than using this annotation directly" is standard text that we put on many @Autoconfigure... annotations. We're basically trying to say that you should use usually the @...Test annotation, but the @Autoconfigure... annotations are here if you need more fine-grained control.

I'm afraid that adding a @DataTransactionTemplateTest feels a bit too specific as well. I think we need to hit the sweet spot of offering useful annotations without having too many of them. You could probably add this annotation to your own code and meta-annotate it with the subset of @AutoconfigureDataJpa annotations that you need.

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
@philwebb philwebb added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants