Class SmartDirtiesContextTestExecutionListener

java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
com.github.seregamorph.testsmartcontext.SmartDirtiesContextTestExecutionListener
All Implemented Interfaces:
org.springframework.core.Ordered, org.springframework.test.context.TestExecutionListener

public class SmartDirtiesContextTestExecutionListener extends org.springframework.test.context.support.AbstractTestExecutionListener
Listener that works in more tricky way than spring DirtiesContextTestExecutionListener. Based on known list (ordered) of tests to execute (reordered via SmartDirtiesClassOrderer for Jupiter classes, SmartDirtiesSuiteListener for TestNG classes or SmartDirtiesPostDiscoveryFilter for JUnit 4 classes), the last test in each group that shares the same configuration (=share the same spring context) will automatically close the ApplicationContext on after-class, which will release resources as well (like Docker containers defined as spring beans). See detailed explanation README.
Author:
Sergey Chernov
See Also:
  • Field Summary

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterTestClass(org.springframework.test.context.TestContext testContext)
     
    void
    beforeTestClass(org.springframework.test.context.TestContext testContext)
     
    int
     

    Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener

    afterTestExecution, afterTestMethod, beforeTestExecution, beforeTestMethod, prepareTestInstance

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SmartDirtiesContextTestExecutionListener

      public SmartDirtiesContextTestExecutionListener()
  • Method Details

    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
      Overrides:
      getOrder in class org.springframework.test.context.support.AbstractTestExecutionListener
    • beforeTestClass

      public void beforeTestClass(org.springframework.test.context.TestContext testContext)
      Specified by:
      beforeTestClass in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      beforeTestClass in class org.springframework.test.context.support.AbstractTestExecutionListener
    • afterTestClass

      public void afterTestClass(org.springframework.test.context.TestContext testContext)
      Specified by:
      afterTestClass in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      afterTestClass in class org.springframework.test.context.support.AbstractTestExecutionListener