Class BaseTestCase

    • Field Detail

      • myTestLogger

        @Nullable
        protected final TestLogger myTestLogger
      • OS_NAME

        protected static final String OS_NAME
        Operating system name (as in the "os.name" environment variable), in lower case.
      • IS_WINDOWS

        protected static final boolean IS_WINDOWS
        Is set under MS Windows and is not set otherwise.
    • Constructor Detail

      • BaseTestCase

        protected BaseTestCase()
      • BaseTestCase

        public BaseTestCase​(String name)
    • Method Detail

      • createTestLogger

        @Nullable
        protected TestLogger createTestLogger()
      • performAfterTestVerification

        protected void performAfterTestVerification()
        Description copied from class: AfterTestHook
        You should implement this method if you want to perform any checks after test was run. You shouldn't do it in the AfterMethod because any exception there will result in that TestNG skip all following tests.
        Overrides:
        performAfterTestVerification in class AfterTestHook
      • log

        protected void log​(String message)
      • setName

        public void setName​(String name)
      • getName

        public String getName()
      • setupSuite

        @BeforeSuite(alwaysRun=true)
        public void setupSuite​(org.testng.ITestContext context)
      • setUpClass

        @BeforeClass
        protected void setUpClass()
                           throws Exception
        Throws:
        Exception
      • setUp

        @BeforeMethod(alwaysRun=true)
        protected void setUp()
                      throws Exception
        Throws:
        Exception
      • enableInfo

        protected void enableInfo()
      • enableDebug

        protected void enableDebug()
      • enableDebug

        protected void enableDebug​(@NotNull
                                   String category)
      • enableAndRecordDebugLog

        @NotNull
        protected StringBuilder enableAndRecordDebugLog()
      • clearFailure

        protected boolean clearFailure()
      • getLoggedFailure

        protected Throwable getLoggedFailure()
      • setLogLevel

        protected void setLogLevel​(org.apache.log4j.Level level)
      • provideWithWindowsOnly

        @DataProvider
        protected String[][] provideWithWindowsOnly()
      • provideWithLinuxMacWindows

        @DataProvider
        protected OSType[][] provideWithLinuxMacWindows()
      • registerAsTempFile

        protected final File registerAsTempFile​(@NotNull
                                                File file)
      • setInternalProperty

        protected void setInternalProperty​(@NotNull
                                           String propKey,
                                           @NotNull
                                           String value)
      • hasCustomInternalProperty

        protected boolean hasCustomInternalProperty​(@NotNull
                                                    String propKey)
      • setInternalProperty

        protected void setInternalProperty​(@NotNull
                                           String propKey,
                                           boolean value)
      • setInternalProperty

        protected void setInternalProperty​(@NotNull
                                           String propKey,
                                           int value)
      • removeInternalProperty

        protected void removeInternalProperty​(@NotNull
                                              String propKey)
      • createTempDir

        protected final File createTempDir()
                                    throws IOException
        Returns a File object for created temp directory.
        Returns:
        a File object for created temp directory
        Throws:
        IOException - if directory creation fails.
      • runAndReportMemoryAllocations

        public void runAndReportMemoryAllocations​(int allocatedMemoryThresholdBytes,
                                                  @NotNull
                                                  Runnable action)
      • waitFor

        public static void waitFor​(@NotNull
                                   Condition condition,
                                   long timeLimitMsec)
      • assertTime

        public static void assertTime​(double maxAllowedExecutionTimeInSecs,
                                      String message,
                                      Runnable r)
      • assertTime

        public static void assertTime​(double maxAllowedExecutionTimeInSecs,
                                      String message,
                                      int numberOfAttempts,
                                      Runnable r)
      • averageExecutionTime

        public static double averageExecutionTime​(Runnable r,
                                                  int numAttempts)
      • isPropertyDefined

        public static boolean isPropertyDefined​(String key)
      • dumpCollection

        public static void dumpCollection​(Iterable it)
      • dumpItems

        public static void dumpItems​(Iterable it)
      • dumpFile

        public static void dumpFile​(File file)
      • threadDump

        public static void threadDump()
      • checkOrderedCollection

        protected <T> void checkOrderedCollection​(@NotNull
                                                  Collection<T> actual,
                                                  T... expected)
      • checkOrderedCollection

        protected <T> void checkOrderedCollection​(@NotNull
                                                  Collection<T> actual)
      • checkUnorderedCollection

        public static <T> void checkUnorderedCollection​(@NotNull
                                                        Collection<T> actual,
                                                        T... expected)
      • checkUnorderedCollection

        protected <T> void checkUnorderedCollection​(@NotNull
                                                    Collection<T> actual)
      • assertMatches

        public static void assertMatches​(String actual,
                                         Pattern pattern)
      • assertMatches

        public static void assertMatches​(String actual,
                                         String pattern)
      • assertContains

        public static <T> void assertContains​(@Nullable
                                              Collection<T> collection,
                                              T... items)
        Checks that the collection contains the given item.
        Type Parameters:
        T - type of items.
        Parameters:
        collection - collection to check.
      • assertContains

        public static <K,​V> void assertContains​(@NotNull
                                                      Map<K,​V> includingMap,
                                                      @NotNull
                                                      Map<K,​V> includedMap)
      • assertNotContains

        public static <T> void assertNotContains​(@Nullable
                                                 Collection<T> collection,
                                                 T... items)
        Checks that the collection contains the given item.
        Type Parameters:
        T - type of items.
        Parameters:
        collection - collection to check.
        items - items to found.
      • assertEmpty

        protected static void assertEmpty​(@Nullable
                                          Collection collection)
        Asserts that collection is empty or null.
        Parameters:
        collection - the collection to check.
      • assertEmpty

        protected static void assertEmpty​(@Nullable
                                          Collection collection,
                                          @Nullable
                                          String message)
        Asserts that collection is empty or null.
        Parameters:
        collection - the collection to check.
      • assertNotEmpty

        public static void assertNotEmpty​(@Nullable
                                          Collection<?> collection)
        Asserts that the collections is not empty (and is not null).
        Parameters:
        collection - the collection to check.
      • assertInstanceOf

        public static <T> void assertInstanceOf​(Object instance,
                                                Class<T> expectedClass)
      • assertNull2

        protected static void assertNull2​(@Nullable
                                          Object object)
        More descriptive assertion than Assert.assertNull(java.lang.Object). If object is not null, it says the object's value (using Object.toString()).
        Parameters:
        object - object that is checking to be null.
      • assertMeaningTextEquals

        protected static void assertMeaningTextEquals​(@Nullable
                                                      String actual,
                                                      @Nullable
                                                      String expected)
      • assertContains

        public static void assertContains​(String textToCheck,
                                          String substring)
      • assertContainsAll

        public static void assertContainsAll​(@Nullable
                                             String text,
                                             @NotNull
                                             String... messages)
      • assertContainsAny

        public static void assertContainsAny​(@Nullable
                                             String text,
                                             @NotNull
                                             String... messages)
      • assertContains

        public static void assertContains​(@Nullable
                                          String textToCheck,
                                          @NotNull
                                          String substring,
                                          boolean caseSensitive)
      • assertContains

        public static void assertContains​(String textToCheck,
                                          Pattern pattern)
      • assertNotContains

        public static void assertNotContains​(@Nullable
                                             String textToCheck,
                                             @NotNull
                                             String substring,
                                             boolean caseSensitive)
      • assertNotContains

        public static void assertNotContains​(String textToCheck,
                                             Pattern pattern)
      • assertHasWithCount

        public static void assertHasWithCount​(String textToCheck,
                                              String substring,
                                              int expectedCount)
      • assertContainsWithCount

        public static void assertContainsWithCount​(String textToCheck,
                                                   String substring,
                                                   int expectedCount)
      • assertSameElements

        public static <T> void assertSameElements​(T[] collection,
                                                  T... expected)
      • assertSameElements

        public static <T> void assertSameElements​(Collection<? extends T> collection,
                                                  T... expected)
      • assertSameElements

        public static <T> void assertSameElements​(Collection<? extends T> collection,
                                                  Collection<T> expected)
      • assertEquals

        public static void assertEquals​(Date exp,
                                        Date got,
                                        long limit)
        Asserts sate and time.
        Parameters:
        exp - what is expected.
        got - what's got (actual).
        limit - max allowed difference, in seconds.
      • assertEquals

        public static void assertEquals​(String message,
                                        Date exp,
                                        Date got,
                                        long limit)
        Asserts sate and time.
        Parameters:
        message - message that will be outputted in case of a fail.
        exp - what is expected.
        got - what's got (actual).
        limit - max allowed difference, in seconds.
      • assertEqualsIgnoreNonBMP

        public static void assertEqualsIgnoreNonBMP​(@Nullable
                                                    String expected,
                                                    @Nullable
                                                    String got)
      • assertArraysEqual

        public static void assertArraysEqual​(int[] expected,
                                             int[] got)
      • assertArraysEqual

        public static void assertArraysEqual​(byte[] expected,
                                             byte[] got)
      • assertSetEquals

        public static <T> void assertSetEquals​(Set<T> actual,
                                               T... expected)
        Applicable for both sorted set and has set. In case of sorted one, the actual set's comparator is used.
        Type Parameters:
        T - type of items
        Parameters:
        actual - the set to check
        expected - expected items, must be no duplicates
        Since:
        8.1
      • assertListEquals

        public static <T> void assertListEquals​(List<T> actual,
                                                @NotNull
                                                T... expected)
      • listFilesOrDie

        @NotNull
        protected File[] listFilesOrDie​(@NotNull
                                        File file)
      • listFilesOrDie

        @NotNull
        protected File[] listFilesOrDie​(@NotNull
                                        File file,
                                        @NotNull
                                        String directory)
      • getTestFiles

        public TestFiles getTestFiles()
      • getTestDataFile

        public File getTestDataFile​(String projectMarker,
                                    String... subs)
      • getTestFilesDataPath

        public Path getTestFilesDataPath​(String projectMarker,
                                         String... subs)
      • getProjectDir

        public Path getProjectDir​(String... sub)
      • doUnderLockedFile

        protected void doUnderLockedFile​(@NotNull
                                         File lock,
                                         @NotNull
                                         BaseTestCase.UnderLockedFile locked)
                                  throws IOException
        Works only under windows. Executes an action under opened for write file (read allowed, but write, move or delete operations are not allowed).
        Parameters:
        lock - directory to lock
        locked - action to run
        Throws:
        IOException - exception
        Since:
        7.1.x
      • doUnderUnreadableLockedFile

        protected void doUnderUnreadableLockedFile​(@NotNull
                                                   File lock,
                                                   @NotNull
                                                   BaseTestCase.UnderLockedFile locked)
                                            throws IOException
        Works only under windows. Executes an action under totally locked file (no read, write, move, delete operations allowed).
        Parameters:
        lock - directory to lock
        locked - action to run
        Throws:
        IOException - exception
        Since:
        7.1.x
      • doUnderLockedDirectory

        protected void doUnderLockedDirectory​(@NotNull
                                              File lock,
                                              @NotNull
                                              BaseTestCase.UnderLockedFile locked)
                                       throws IOException
        Works only under windows. Executes an action under locked directory.
        Parameters:
        lock - directory to lock
        locked - action to run
        Throws:
        IOException - exception
        Since:
        7.1.x
      • assertGreater

        protected static void assertGreater​(int actual,
                                            int lowBound)
      • assertGreater

        protected static void assertGreater​(long actual,
                                            long lowBound)
      • assertGreaterOrEquals

        protected static void assertGreaterOrEquals​(long actual,
                                                    long lowBound)
      • assertMapping

        protected static <K,​V> void assertMapping​(@NotNull
                                                        Map<K,​V> map,
                                                        @NotNull
                                                        K key,
                                                        @NotNull
                                                        V expectedValue)
      • assertMap

        protected static <K,​V> void assertMap​(@Nullable
                                                    Map<K,​V> map,
                                                    Object... expected)
      • createSet

        @NotNull
        protected <T> Set<T> createSet​(T... params)
      • createMap

        @NotNull
        protected <K,​V> Map<K,​V> createMap​(Object... params)
      • toProvide

        public static Object[][] toProvide​(Object... items)
      • provideWithBooleans

        @DataProvider
        protected static Boolean[][] provideWithBooleans()
      • assertTimestampEquals

        public static void assertTimestampEquals​(Date actual,
                                                 Date expected)
      • assertExceptionThrown

        public static void assertExceptionThrown​(@NotNull
                                                 Callable callable,
                                                 @NotNull
                                                 Class<? extends Exception> expected)
      • assertExceptionThrown

        public static void assertExceptionThrown​(@NotNull
                                                 Callable callable,
                                                 @NotNull
                                                 Class<? extends Exception> expected,
                                                 @Nullable
                                                 String expectedMessage)
      • assertExceptionThrown

        public static void assertExceptionThrown​(@NotNull
                                                 VoidCallable callable,
                                                 @NotNull
                                                 Class<? extends Exception> expected)
      • assertExceptionThrown

        public static void assertExceptionThrown​(@NotNull
                                                 VoidCallable callable,
                                                 @NotNull
                                                 Class<? extends Exception> expected,
                                                 @Nullable
                                                 String expectedMessage)
      • trueFalseDataProvider

        @DataProvider(name="true,false")
        protected Object[][] trueFalseDataProvider()