I've spent the past 2 weeks trying to figure out why the transactions
in our JPA tests no longer work correctly, the problem has been that
too many things have changed at once - migrated from JUnit3 to TestNG,
from Spring 2.5.6 to 3.0.0.M4, changed all the test to Spring
TestContext framework style, and in the background other developers
have made some strategic changes to the way we use JPA !
To add additional confusion, this problem doesn't manifest itself when
running the tests inside Eclipse ("developer mode") but only when
running them from Ant ("continuous build mode") so it has left
everyone else in the project with a bit of a loss of confidence in
myself as they no longer trust the continuous build results :-(
However I've now narrowed it down to a fairly straightforward sample
project which clearly demonstrates the problem.
If the tests are run with a timeout attribute, they fail at
EntityManager.flush() because there is no transaction.
If the timeout is set to zero, they pass.
(they run quickly, there's no question that the timeout is too short,
the problem is just an artefact of a timeout being set).
I'm setting the timeout using an IAnnotationTransformer which sets a
default value on all tests that don't already have an explicit timeout
setting. We had to use @Test(timeout) rather than the overall timeOut
setting in the Ant task, because the latter simply terminates the
process abruptly causing a loss of data (test results and coverage)
when it fires.
I just found that you already have a JIRA issue for this -
http://jira.opensymphony.com/browse/TESTNG-280
I can attach my sample project if necessary.
We're using Toplink Essentials from Glassfish 2.1 with Spring 3.0.0.M4
(to get class-level @DirtiesContext) and TestNG 5.10.
Unfortunately this is a complete show-stopper for us. But I really
don't want to be forced back to the dark side, there are so many
benefits to using TestNG. If it's not possible to get a fix out
quickly, I'd appreciate some pointers as to where to look in order to
create my own patch.
Thanks
Ed