Class TestNamesMatcher


  • public final class TestNamesMatcher
    extends java.lang.Object
    The class to work with "-testnames", "-ignoreMissedTestNames", and VM argument "-Dtestng.ignore.missed.testnames". If both "-ignoreMissedTestNames" and VM argument "-Dtestng.ignore.missed.testnames" are set, then either of them has "true" value will enable the feature to ingore partially missed test names and run those existing test names.
    • Field Detail

      • LOGGER

        private static final Logger LOGGER
      • cloneSuites

        private final java.util.List<XmlSuite> cloneSuites
      • matchedTestNames

        private final java.util.List<java.lang.String> matchedTestNames
      • matchedTests

        private final java.util.List<XmlTest> matchedTests
      • testNames

        private final java.util.List<java.lang.String> testNames
      • ignoreMissedTestNames

        private final boolean ignoreMissedTestNames
    • Constructor Detail

      • TestNamesMatcher

        public TestNamesMatcher​(XmlSuite xmlSuite,
                                java.util.List<java.lang.String> testNames)
      • TestNamesMatcher

        public TestNamesMatcher​(XmlSuite xmlSuite,
                                java.util.List<java.lang.String> testNames,
                                boolean ignoreMissedTestNames)
    • Method Detail

      • cloneIfContainsTestsWithNamesMatchingAny

        private void cloneIfContainsTestsWithNamesMatchingAny​(XmlSuite xmlSuite,
                                                              java.util.List<java.lang.String> testNames)
        Recursive search the given testNames from the current XmlSuite and its child suites.
        Parameters:
        xmlSuite - The XmlSuite to work with.
        testNames - The list of testnames to iterate through
      • getSuitesMatchingTestNames

        public java.util.List<XmlSuite> getSuitesMatchingTestNames()
      • validateMissMatchedTestNames

        public boolean validateMissMatchedTestNames()
        Do validation for testNames and notify users if any testNames are missed in suite. This method is also used to decide how to run test suite when test names are given. In legacy logic, if test names are given and exist in suite, then run them; if any of them do not exist in suite, then throw exception and exit. After ignoreMissedTestNames is introduced, if ignoreMissedTestNames is enabled, then any of the given test names exist in suite will be run, and print warning message to tell those test names do not exist in suite.
        Returns:
        boolean if ignoreMissedTestNames disabled, then return true if no missed test names in suite, otherwise throw TestNGException; if ignoreMissedTestNames enabled, then return true if any test names exist in suite, otehrwise (all given test names are missed) throw TestNGException.
      • getMissedTestNames

        public java.util.List<java.lang.String> getMissedTestNames()
      • getMatchedTests

        public java.util.List<XmlTest> getMatchedTests()
      • addIfNotNull

        private void addIfNotNull​(XmlSuite xmlSuite)
      • cloneIfSuiteContainTestsWithNamesMatchingAny

        private XmlSuite cloneIfSuiteContainTestsWithNamesMatchingAny​(XmlSuite suite)