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

No backing TransactionOperations configured during test execution #10813

Closed
Nahuel92 opened this issue May 10, 2024 · 1 comment
Closed

No backing TransactionOperations configured during test execution #10813

Nahuel92 opened this issue May 10, 2024 · 1 comment

Comments

@Nahuel92
Copy link

Nahuel92 commented May 10, 2024

Expected Behavior

Mocked repositories with methods annotated with @Transactional should work during testing. It doesn't matter if it is:

  • @jakarta.transaction.Transactional
  • @io.micronaut.transaction.annotation.Transactional

The bug manifests itself with both annotations.

Actual Behaviour

Mocked repositories with methods annotated with @Transactional fail during testing with o.micronaut.context.exceptions.ConfigurationException: No backing TransactionOperations configured. Check your configuration and try again.

Bug test cases

Annotation / Annotated on Repository Repository method Tests execution result 1 Production execution result
@Transactional 2 Yes No Pass Fail
@Transactional 2 No Yes Fail Works well
@Transactional 2 Yes Yes Fail Works well

Steps To Reproduce

For your convenience, you can use the provided app example. But here are the steps anyway:

  1. Create an app with Micronaut Data JDBC + H2 driver (for instance).
  2. Create a Repository (annotate it with @Repository).
  3. Create a repository method and annotate it with @Transactional.
  4. Create a Service (it may not be necessary, I haven't tested without a service class).
  5. Inject the Repository and create a dummy service method calling the repository method.
  6. Create a Service test (annotate it with @MicronautTest), mock the Repository with Mockito and inject it into the ApplicationContext with @MockBean(Repository.class) (to replace real Repository).
  7. Execute the test and see it failing with io.micronaut.context.exceptions.ConfigurationException: No backing TransactionOperations configured. Check your configuration and try again.

If the @Transactional annotation is moved to a class level, the test will pass, but the Repository method will fail at runtime.

If the example app isn't clear enough, please let me know and I'll add more information. Thanks.

Environment Information

  • Windows/ Linux (it doesn't really matter).
  • JDK 21 (I don't think it matters).
  • jUnit 5.
  • Mockito.

Example Application

https://github.com/Nahuel92/Micronaut-test-bug

I added my findings to the README.md file.

Please set MICRONAUT_ENVIRONMENTS=prod before starting the app.

Version

4.4.2

Footnotes

  1. Tests mock repositories with @MockBean(RepositoryClass.class).

  2. It doesn't matter whether it's @jakarta.transaction.Transactional
    or @io.micronaut.transaction.annotation.Transactional. 2 3

@Nahuel92
Copy link
Author

Nahuel92 commented May 23, 2024

Closing as per dstepanov's comment here:

micronaut-projects/micronaut-data#2943 (comment)

Opened a new improvement suggestion/discussion opener issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant