-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Support @Transactional on TestNG @BeforeClass methods in the TestContext framework [SPR-11397] #16024
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
Comments
Sam Brannen commented Hi Adib, Thanks for taking the time to submit such a detailed issue and for submitting the pull request. I will take a look at your recommendations there. Regarding your question:
The issue here is that Now, having said that, all is not lost in your case... The support for managing transactions for tests is governed by the Consider the following note from the "Testing" chapter of the reference manual (see the TestNG support classes section).
In other words, you do not have to extend The default implementation of Give it a try! Regards, Sam |
Sam Brannen commented Resolving this issue as Works as Designed. See previous comments for details. Also, please note that the requested documentation enhancement is now covered in #16026. |
Adib Saikali commented Thanks for clarifying the options, I will try making my own base class, that behaves the way I want. |
Sam Brannen commented Hi Adib, Please let us know if that works out for you, especially since other developers might be interested in your solution. Thanks, Sam |
Giovanni commented Good morning, I'd like to know if this issue has been resolved, or if there is anything I can do to resolve it. |
Sam Brannen commented Yes, this issue was resolved as Works as Designed on February 6, 2014. Please see the above comments. I am now closing this issue permanently. |
Adib Saikali opened SPR-11397 and commented
When using the Spring TestContext Framework with TestNG it is not possible to annotate a TestNG
@BeforeClass
method with@Transactional
and have it executed with a Spring-managed transaction, as depicted in the example below.With the current implementation of
AbstractTransactionalTestNGSpringContextTests
it is possible to refer to any autowired variable within an@BeforeClass
method. It seems that by the the time@BeforeClass
method is invoked Spring is fully initialized and therefore any@Transactional
method should be working. It feels counter-intuitive that@Transactional
and@BeforeClass
in TestNG don't work with each other. As an aside, I understand why JUnit's@BeforeClass
does not work with@Transactional
.One of the primary reasons for using TestNG over JUnit is that TestNG makes writing integration tests easier because of the way
@BeforeClass
works in TestNG. So in many integration testing scenarios it is possible that an@BeforeMethod
method needs to read data from JPA or do some other prep work for the test that is@Transactional
.Can you please make
@BeforeClass
and@Transactional
work together for TestNG?In the meantime I have sent a pull request on GitHub to update the docs so that they at least warn users that
@BeforeClass
and@Transactional
don't work with each other.Affects: 3.0 GA
Issue Links:
The text was updated successfully, but these errors were encountered: