Class BaseTest

  • Direct Known Subclasses:
    ComponentTest, ModuleTest, SubsystemTest, SystemTest

    public abstract class BaseTest
    extends org.assertj.core.api.Assertions
    This is the abstract base class for all tests. In most cases it will be convenient to extend this class.

    Although it does not contain abstract methods, the class itself is declared abstract to clarify its purpose.

    This class provides final methods setUp() and tearDown() which call protected methods doSetUp() and doTearDown() internally.
    Both methods doSetUp() and doTearDown() are left empty here. If some default behaviour is desired during test setup or teardown these methods should be overridden by the subclass.
    Implementations must call the super implementation. This call should always happen at the beginning of the implementation. This helps to avoid confusion of call orders.

    The following listing should clarify the intention:
     public class MyTest extends BaseTest {
    
       @Override
       protected void doSetUp() {
    
         super.doSetUp();
         // ... my code
       }
     }
     
    Additional value is provided by isInitialSetup() that may be helpful for specific implementations of doSetUp() where you want to do some cleanup only once for the test-class rather than for every test method. Unlike BeforeClass this can be used in non-static method code so you have access to injected dependencies.
    Author:
    shuber, jmolinar
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static boolean INITIALIZED
      Indicates if the test class is to be set up for the first time.
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseTest()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doSetUp()
      Provides initialization previous to the creation of the text fixture.
      protected void doTearDown()
      Provides clean up after tests.
      protected boolean isInitialSetup()  
      void setUp()
      Suggests to use doSetUp() method before each tests.
      void tearDown()
      Suggests to use doTearDown() method before each tests.
      • Methods inherited from class org.assertj.core.api.Assertions

        allOf, allOf, anyOf, anyOf, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThatCode, assertThatExceptionOfType, assertThatIllegalArgumentException, assertThatIllegalStateException, assertThatIOException, assertThatNullPointerException, assertThatThrownBy, assertThatThrownBy, atIndex, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, catchThrowable, catchThrowableOfType, contentOf, contentOf, contentOf, contentOf, contentOf, contentOf, doesNotHave, entry, extractProperty, extractProperty, fail, fail, fail, failBecauseExceptionWasNotThrown, filter, filter, from, in, linesOf, linesOf, linesOf, linesOf, linesOf, linesOf, not, not, notIn, offset, offset, registerCustomDateFormat, registerCustomDateFormat, registerFormatterForType, setAllowComparingPrivateFields, setAllowExtractingPrivateFields, setLenientDateParsing, setMaxElementsForPrinting, setMaxLengthForSingleLineDescription, setRemoveAssertJRelatedElementsFromStackTrace, shouldHaveThrown, tuple, useDefaultDateFormatsOnly, useDefaultRepresentation, useRepresentation, within, within, within, within, within, within, within, within, within, withinPercentage, withinPercentage, withinPercentage, withPrecision, withPrecision
    • Field Detail

      • INITIALIZED

        protected static boolean INITIALIZED
        Indicates if the test class is to be set up for the first time. true indicates that the class has already been set up (e.g., database setup) for the execution of an preceding test method.
    • Constructor Detail

      • BaseTest

        public BaseTest()
    • Method Detail

      • setUp

        @BeforeEach
        public final void setUp()
        Suggests to use doSetUp() method before each tests.
      • tearDown

        @AfterEach
        public final void tearDown()
        Suggests to use doTearDown() method before each tests.
      • isInitialSetup

        protected boolean isInitialSetup()
        Returns:
        true if this JUnit class is invoked for the first time (first test method is called), false otherwise (if this is a subsequent invocation).
      • doSetUp

        protected void doSetUp()
        Provides initialization previous to the creation of the text fixture.
      • doTearDown

        protected void doTearDown()
        Provides clean up after tests.