You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
For your convenience, you can use the provided app example. But here are the steps anyway:
Create an app with Micronaut Data JDBC + H2 driver (for instance).
Create a Repository (annotate it with @Repository).
Create a repository method and annotate it with @Transactional.
Create a Service (it may not be necessary, I haven't tested without a service class).
Inject the Repository and create a dummy service method calling the repository method.
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).
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.
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 witho.micronaut.context.exceptions.ConfigurationException: No backing TransactionOperations configured. Check your configuration and try again
.Bug test cases
@Transactional
2@Transactional
2@Transactional
2Steps To Reproduce
For your convenience, you can use the provided app example. But here are the steps anyway:
@Repository
).@Transactional
.@MicronautTest
), mock the Repository with Mockito and inject it into the ApplicationContext with@MockBean(Repository.class)
(to replace real Repository).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
Example Application
https://github.com/Nahuel92/poc-projects/tree/master/micronaut/Micronaut-test-bug
I added my findings to the README.md file.
Version
4.4.2
Footnotes
Tests mock repositories with
@MockBean(RepositoryClass.class)
. ↩It doesn't matter whether it's
@jakarta.transaction.Transactional
or
@io.micronaut.transaction.annotation.Transactional
. ↩ ↩2 ↩3The text was updated successfully, but these errors were encountered: