title: JUnit - before method
body: <p>I need to execute some piece of code before every JUnit test method. To execute this piece of code I use SpringTest class AbstractTestExecutionListener and its child TransactionContextTestExecutionListener.</p>
  
  <p>This is code:</p>
  
  <pre><code>public class TransactionContextTestExecutionListener extends AbstractTestExecutionListener{
  
      private static final Logger logger = Logger.getLogger(TransactionContextTestExecutionListener.class);
  
  
      @Override
      public void beforeTestMethod(TestContext testContext) throws Exception {
          Object ctx = testContext.getApplicationContext().getBean(Context.class);
  }
  </code></pre>
  
  <p>My JUnit class looks like:</p>
  
  <pre><code>@ContextConfiguration(locations = "classpath:/META-INF/spring-test/tests-context.xml")
  @RunWith(SpringJUnit4ClassRunner.class)
  @TestExecutionListeners(TransactionContextTestExecutionListener.class)
  @Transactional
  public class SelectQueryBuilderTest {}
  </code></pre>
  
  <p>Problem is that beforeTestMethod method is only called before first executed
  test method. It is not called before all of the rest ones.</p>
  
  <p>Is problem in configuration? Any idea?</p>
  
  <p>Thanks</p>