title: Maven Spring tests fail when run together, but succeed individually (ehcache closed, IllegalTransactionStateException)
body: <p>We're using Maven/Surefire and Spring/Hibernate transactional tests for a fairly large web application. There are 138 Test* classes, running a total of 1178 tests.</p>
  
  <p>A straightforward <code>mvn test</code> will generate 82 errors, the nature of which tend to imply a corrupt application context:</p>
  
  <p>Many of these:  </p>
  
  <pre><code>IllegalTransactionStateException: Pre-bound JDBC Connection found!
  </code></pre>
  
  <p>A few of these:  </p>
  
  <pre><code>NoSuchMethodError: org.hibernate.cache.CacheException.&lt;init&gt;(Ljava/lang/Exception;)V
  </code></pre>
  
  <p>For every failed test, running the test class individually <code>mvn test -Dtest=TestFailingClass</code> succeeds. Indeed, using -<code>Dtest=TestClass1,TestClass2,Etc</code> with various subsets of all my test classes succeeds or fails in different ways. For instance, running only the failing test classes succeeds with 0 errors.</p>
  
  <p>With no apparent means to control the order of classes tested by Surefire, I have a difficult time determining which of my test classes seem to be leaving the context in a bad state.</p>
  
  <p>What I'm looking for is a strategy to help determine what is happening in some kind of deterministic manner. I can certainly see the order of tests run from the log, but I cannot reproduce that order controllably.</p>
  
  <p>And of course, suggestions for what to do about it ...</p>