Top Description Fields Constructors Methods
org.testng

public Class TestNG

extends Object
Class Inheritance
Annotations
@SuppressWarnings:unused, unchecked, rawtypes
Static Imports
org.testng.ListenerComparator.sort, org.testng.internal.Utils.defaultIfStringEmpty, .Utils.isStringEmpty, .Utils.isStringNotEmpty

This class is the main entry point for running tests in the TestNG framework. Users can create their own TestNG object and invoke it in many different ways: You can also define which groups to include or exclude, assign parameters, etc...

The command line parameters are:

Please consult documentation for more details.

FIXME: should support more than simple paths for suite xmls

Author
Cedric Beust
See Also
usage()

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_COMMAND_LINE_SUITE_NAME

The default name for a suite launched from the command line

public static final String
DEFAULT_COMMAND_LINE_TEST_NAME

The default name for a test launched from the command line

private static final ITestObjectFactory
public static final String
DEFAULT_OUTPUTDIR

The default name of the result's output directory (keep public, used by Eclipse).

private static final String
public static final Integer
private ExitCode
private final ExitCodeListener
private boolean
private static final Logger
LOGGER

This class' log4testng Logger.

private final Map<Class<? extends IAlterSuiteListener>, IAlterSuiteListener>
private boolean
private IAnnotationTransformer
private final Map<Class<? extends IClassListener>, IClassListener>
private List<XmlSuite>
private List<String>
private Class<?>[]
private XmlSuite.FailurePolicy
private IConfigurable
private IConfiguration
private final Map<Class<? extends IDataProviderInterceptor>, IDataProviderInterceptor>
private final Map<Class<? extends IDataProviderListener>, IDataProviderListener>
private Integer
private final IAnnotationTransformer
private String
private String
protected long
private String[]
private final Map<Class<? extends IExecutionVisualiser>, IExecutionVisualiser>
private boolean
private boolean
private Boolean
private IHookable
private boolean
private String[]
private static TestNG
private final Map<Class<? extends IInvokedMethodListener>, IInvokedMethodListener>
private boolean
private String
private static JCommander
private final List<String>
private final Map<String, Integer>
private final List<IMethodInterceptor>
private ITestObjectFactory
private String
private XmlSuite.ParallelMode
private Boolean
private boolean
private final Map<Class<? extends IReporter>, IReporter>
private final Set<XmlMethodSelector>
private URLClassLoader
private Boolean
protected long
private List<String>
private final Map<Class<? extends ISuiteListener>, ISuiteListener>
protected List<XmlSuite>
private Integer
private final Map<Class<? extends ITestListener>, ITestListener>
private List<String>
m_testNames

The list of test names to run from the given suite

private ITestRunnerFactory
private int
protected boolean
private Integer
m_verbose

If m_verbose gets set, it will override the verbose setting in testng.xml

private String
m_xmlPathInJar

The path of the testng.xml file inside the jar file

private final Map<Class<? extends ITestNGListener>, ITestNGListener>

Constructor Summary

AccessConstructor and Description
public
TestNG()

Default constructor.

public
TestNG(boolean
Whether or not any default reports should be added to tests.
useDefaultListeners
)

Used by maven2 to have 0 output of any kind come out of testng.

Method Summary

Modifier and TypeMethod and Description
public void
addClassLoader(final ClassLoader
The class loader to add
loader
)

Add a class loader to the searchable loaders.

public void
addListener(Object
The listener to add
listener
)

Deprecated Use addListener(ITestNGListener) instead
public void
private void
public void
addMethodSelector(String className, int priority)

public void
private void
addReporter(Class<? extends IReporter> r)

private void
addReporter(ReporterConfig reporterConfig)

private void
private void
addServiceLoaderListeners()

Using reflection to remain Java 5 compliant.

public void
alwaysRunListeners(boolean alwaysRun)

protected void
configure(CommandLineArgs
The command line parameters
cla
)

Configure the TestNG instance based on the command line parameters.

public void
configure(Map<K, V>
The command line
cmdLineArgs
)

Deprecated use new configure(CommandLineArgs) method
This method is invoked by Maven's Surefire to configure the runner, do not remove unless you know for sure that Surefire has been updated to use the new configure(CommandLineArgs) method.
private List<XmlSuite>
private List<XmlSuite>

Returns:

a list of XmlSuite objects that represent the list of classes and methods passed in parameter.
createCommandLineSuitesForMethods
(List<String>
a string with the form "com.example.Foo.f1,com.example.Bar.f2"
commandLineMethods
)

private SuiteRunner
createSuiteRunner(XmlSuite xmlSuite)

Creates a suite runner and configures its initial state

private void
createSuiteRunners(SuiteRunnerMap
Map with XMLSuite as key and it's respective SuiteRunner as value. This is updated as part of this method call
suiteRunnerMap
,
XmlSuite
Xml Suite (and its children) for which SuiteRunners are created
xmlSuite
)

Creates the SuiteRunners and populates the suite runner map with this information

private static void
pack-priv static void
private void
generateReports(List<ISuite> suiteRunners)

public IAnnotationTransformer
public XmlSuite.FailurePolicy

Returns:

config failure policy
getConfigFailurePolicy
()

Returns the configuration failure policy.

protected IConfiguration
public static TestNG

Returns:

The default instance
getDefault
()

Deprecated since 5.1
public String

Returns:

the defaultSuiteName
getDefaultSuiteName
()

public String

Returns:

the defaultTestName
getDefaultTestName
()

protected long
public ListenerComparator
public String
private OverrideProcessor
public boolean
public Set<IReporter>
public List<ITestNGListener>
protected long
public int
public List<ISuiteListener>
public Integer
public List<ITestListener>
private int

Returns:

the verbose level, checking in order: the verbose level on the suite, the verbose level on the TestNG object, or 1.
getVerbose
(XmlSuite xmlSuite)

public boolean

Returns:

true if at least one test failed.
hasFailure
()

public boolean

Returns:

true if at least one test failed within success percentage.
hasFailureWithinSuccessPercentage
()

public boolean

Returns:

true if at least one test was skipped.
hasSkip
()

private void
init(boolean useDefaultListeners)

private void
private void
private static void
initializeCommandLineSuitesGroups(XmlSuite s, boolean hasIncludedGroups, String[] m_includedGroups, boolean hasExcludedGroups, String[] m_excludedGroups)

private void
private void
private void
public void
initializeEverything()

Invoked by the remote runner.

public void
public boolean
public boolean
public static void
main(String[]
the TestNG command line parameters.
argv
)

The TestNG entry point for command line execution.

private static <E> void
maybeAddListener(Map<Class<? extends E>, E> map, E value)

private static <E> void
maybeAddListener(Map<Class<? extends E>, E> map, Class<? extends E> type, E value, boolean quiet)

private IReporter
newReporterInstance(ReporterConfig config)

Creates a reporter based on the configuration

private static int
private Collection<XmlSuite>
parseSuite(String suitePath)

private void
private void
populateSuiteGraph(IDynamicGraph<ISuite>
dynamic graph representing the reverse hierarchy of SuiteRunners
suiteGraph
,
SuiteRunnerMap
Map with XMLSuite as key and its respective SuiteRunner as value
suiteRunnerMap
,
XmlSuite
XML Suite
xmlSuite
)

Populates the dynamic graph with the reverse hierarchy of suites.

public static TestNG

Returns:

The TestNG instance
privateMain
(String[]
The param arguments
argv
,
ITestListener
The listener
listener
)

Note

this method is not part of the public API and is meant for internal usage only.

private Collection<XmlSuite>
private void
public void
public void
run()

Run TestNG.

private void
runExecutionListeners(boolean start)

private void
protected List<ISuite>

Returns:

- List of suites that were run as ISuite objects.
runSuites
()

Run the test suites.

public List<ISuite>

Returns:

The locally run suites
runSuitesLocally
()

This needs to be public for maven2, for now..At least until an alternative mechanism is found.

private void
runSuitesSequentially(XmlSuite
XML Suite to be executed
xmlSuite
,
SuiteRunnerMap
Maps XmlSuites to respective ISuite
suiteRunnerMap
,
int
verbose level
verbose
,
String
default suite name
defaultSuiteName
)

Recursively runs suites.

private void
sanityCheck()

Before suites are executed, do a sanity check to ensure all required conditions are met.

private void
public void
public void
setConfigFailurePolicy(XmlSuite.FailurePolicy
the configuration failure policy
failurePolicy
)

Sets the policy for whether or not to ever invoke a configuration method again after it has failed once.

private void
public void
public void
setDefaultSuiteName(String
the defaultSuiteName to set
defaultSuiteName
)

public void
setDefaultTestName(String
the defaultTestName to set
defaultTestName
)

public void
setExcludedGroups(String
A list of group names separated by a comma.
groups
)

Define which groups will be excluded from this run.

public void
public void
setGenerateResultsPerSuite(boolean generateResultsPerSuite)

public void
public void
setGroups(String
A list of group names separated by a comma.
groups
)

Define which groups will be included from this run.

private void
private void
setIgnoreMissedTestNames(boolean ignoreMissedTestNames)

public void
public void
setListenerClasses(List<Class<? extends ITestNGListener>>
A list of classes, which must be either ISuiteListener, ITestListener or IReporter
classes
)

Define which listeners to user for this run.

public void
public void
public void
setListenersToSkipFromBeingWiredInViaServiceLoaders(String...
- An array of fully qualified class names that should be skipped from being wired in via service loaders.
listeners
)

public void
public void
public void
public void
setOutputDirectory(final String
The directory.
outputdir
)

Sets the output directory where the reports will be created.

public void
setParallel(String
Define whether this run will be run in parallel mode.
parallel
)

Deprecated Use #setParallel(XmlSuite.ParallelMode) instead
public void
public void
setPreserveOrder(boolean b)

public void
setRandomizeSuites(boolean randomizeSuites)

public void
setReportAllDataDrivenTestsAsSkipped(boolean reportAllDataDrivenTestsAsSkipped)

public void
public void
public void
setSourcePath(String
The path
path
)

Deprecated
This method is invoked by Maven's Surefire, only remove it once Surefire has been modified to no longer call it.
public void
setSuiteThreadPoolSize(Integer suiteThreadPoolSize)

public void
setTestClasses(Class<T>[]
An array of classes that contain TestNG annotations.
classes
)

Set the test classes to be run by this TestNG object.

public void
setTestJar(String
- Path of the jar
jarPath
)

Sets a jar containing a testng.xml file.

public void
setTestNames(List<String>
Only run the specified tests from the suite.
testNames
)

protected void
private void
setTestRunnerFactoryClass(Class<? extends ITestRunnerFactory> testRunnerFactoryClass)

public void
setTestSuites(List<String>
A list of paths to one more XML files defining the tests. For example:
TestNG tng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("c:/tests/testng1.xml");
suites.add("c:/tests/testng2.xml");
tng.setTestSuites(suites);
tng.run();
suites
)

Set the suites file names to be run by this TestNG object.

public void
setThreadCount(int
Define the number of threads in the thread pool.
threadCount
)

public void
setUseDefaultListeners(boolean
If true before run(), the default listeners will not be used.
  • org.testng.reporters.TestHTMLReporter
  • org.testng.reporters.JUnitXMLReporter
  • org.testng.reporters.XMLReporter
useDefaultListeners
)

public void
setVerbose(int
the verbosity level (0 to 10 where 10 is most detailed) Actually, this is a lie: you can specify -1 and this will put TestNG in debug mode (no longer slicing off stack traces and all).
verbose
)

Sets the level of verbosity.

public void
setXmlPathInJar(String
Sets the path to the XML file in the test jar file.
xmlPathInJar
)

public void
setXmlSuites(List<XmlSuite>
- The list of XmlSuite objects.
suites
)

Specifies the XmlSuite objects to run.

public void
public void
private String[]
splitMethod(String m)

Given a string com.example.Foo.f1, return an array where [0] is the class and [1] is the method.

public void
toggleFailureIfAllTestsWereSkipped(boolean
- Whether TestNG should enable/disable failing when all the tests were skipped and nothing was run (Mostly when a test is powered by a data provider and when the data provider itself fails causing all tests to skip).
failIfAllTestsSkipped
)

private static void
public boolean
protected static void
validateCommandLineParameters(CommandLineArgs
The command line to check
args
)

Double check that the command line parameters are valid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait