title: How to shutdown application context between tests
body: <p>I have 3 groups of tests: unit, integration, acceptance.</p>
  
  <ul>
  <li>Latter two groups launches ApplicationContext: minimal for "integration" and full for "acceptance". </li>
  <li>Both application contexts register queue subscriber.</li>
  <li>Application contexts are deregistered at the end of entire test run (<code>@RunWith(SpringRunner.class)</code>)</li>
  </ul>
  
  <p>When I run "all tests" 2 different application contexts are started and I have duplicate queue subscribers.</p>
  
  <p>I know following workarounds for this subscribers duplication:</p>
  
  <ul>
  <li>never run integration and acceptance test together</li>
  <li>use "acceptance" application context for "integration" tests. Downside: test run will take longer time.</li>
  <li>add static registry and manually add/remove listeners. Downside: too complex and easy-to-forget</li>
  </ul>
  
  <p>Are there any convinient way to unload application context after a group of tests?</p>
  
  <h2>UPDATE based on <em>ndrone</em> answer</h2>
  
  <ul>
  <li><code>@DirtiesContext</code> is a perfect match</li>
  <li>one more option is to limit cached ApplicationContexts count to one with <code>spring.test.context.cache.maxSize=1</code></li>
  </ul>
  
  <h2>Test superclass example with dirties context</h2>
  
  <pre><code>    @RunWith(SpringRunner.class)
      @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
      @TestExecutionListeners({FlywayTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
      @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
      public abstract class AcceptanceTest {}
  </code></pre>