title: How to rollback unit test while service layer is @Transactional
body: <p>I am using Spring Boot 1.5.2.RELEASE and my service classes is annotated with </p>
  
  <pre><code>@Service
  @Transactional(rollbackFor = Exception.class)
  </code></pre>
  
  <p>My unit test class is annotated with:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  </code></pre>
  
  <p>I wish to roll back changes made in the database by unit test methods after test is finished.</p>
  
  <p><strong>One of the proposed solutions</strong> is to add <code>@Transactional</code> annotation over the test class, I tried it but this solution produces some issues, is that sometimes the test transaction is rolled back (even without no exceptions thrown!) before the service transaction is completed.</p>
  
  <p>Is there another good solution to rollback test?</p>