-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
@Transactional annotation doesn't work in JUnit tests #6463
Comments
This is not how @transactional works, it just starts a regular transaction that would be committed as normal. In addition this transaction is not propagated over JAX-RS calls, so even if it did roll back on the client side the server side transaction would commit as normal. This would need a new annotation (we have talked about @TestTransaction in the past), and would require some work to automatically propagate the transaction over HTTP. |
With Spring (and of course SpringBoot), PS: I am sure this is the behavior with |
@sudhirtumati is right. Anyone coming from Spring Boot world would expect a "transactional test" to perform all persistence operations within a test-owned transaction that is rolled back at the end of that test. The documentation mentions the concept of transactional tests both in the transaction guide and testing guide, but doesn't fully explain what the behavior is. This is undoubtedly making people jump to the wrong conclusion. I was convinced I was doing something wrong until I came across this issue. P.S. Do you have a suggested methodology, even if manual, that would allow Spring-like behavior? I tried to call |
This allows you to run tests in a rollback only transaction. Fixes quarkusio#6463
This allows you to run tests in a rollback only transaction. Fixes quarkusio#6463
This allows you to run tests in a rollback only transaction. Fixes quarkusio#6463
This allows you to run tests in a rollback only transaction. Fixes quarkusio#6463
This only works in Spring when you are running tests against the in-memory spring context - it does not work for RestAssured style tests |
Describe the bug
Database changes made during JUnit tests are not rolled back even when test class and/or method is marked @transactional
Expected behavior
Database changes must be rolled back when test method is annotated with
@Transactional
Actual behavior
Database changes are not rolled back causing other tests to fail
To Reproduce
Steps to reproduce the behavior:
mvn clean test
from command lineConfiguration
Screenshots
N/A
Environment (please complete the following information):
uname -a
orver
:Linux SUDHIR-TP 4.19.84-microsoft-standard #1 SMP Wed Nov 13 11:44:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
java -version
:1.1.0.Final
Additional context
(Add any other context about the problem here.)
The text was updated successfully, but these errors were encountered: