title: Grails: Transactions in Integration Tests
body: <p>I have a very simple setup - a controller that invokes a method on a service. In this service, I save an object to the DB and also send a JMS message to a queue - once it is saved - using an injected JMSTemplate. The service has transactions enabled by default.</p>
  
  <p>When testing this manually - with the ActiveMQ server down - an exception is thrown and the transaction is rolled back - with the net effect that the object is also not saved to the DB. All good.</p>
  
  <p>However, when I run this through an integration test (with ActiveMQ still down), the assert, that I have in place to check that the object did not get saved in the DB using a count query after I invoke the controller, fails saying that the count is 1. I have confirmed that the DB does not have any of these objects when the test starts by adding another assert at the beginning of the test to ensure that the count is 0.</p>
  
  <p>Is this expected behaviour (maybe due to the nature of transactions in an integration test environment) or am I potentially doing something wrong? The exception is still being thrown because the JMS server is down - and it is a RuntimeException.</p>
  
  <p><a href="https://stackoverflow.com/questions/4141601/grails-integration-tests-and-transactions">Grails integration tests and transactions</a> gives an impression that this is to be expected - in which case, are there any suggestions around best practices for how to test transactional behaviour in integration tests?</p>