public class TestNG extends Object
The command line parameters are:
outputdir: specify the output directory
class_name: specifies one or several class names
jar_name: specifies the jar containing the tests
src1;src2: ; separated list of source directories (used only when
javadoc annotations are used)
Please consult documentation for more details.
FIXME: should support more than simple paths for suite xmls
usage()| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_COMMAND_LINE_SUITE_NAME
The default name for a suite launched from the command line
|
static String |
DEFAULT_COMMAND_LINE_TEST_NAME
The default name for a test launched from the command line
|
static String |
DEFAULT_OUTPUTDIR
The default name of the result's output directory (keep public, used by Eclipse).
|
static Integer |
DEFAULT_VERBOSE |
protected long |
m_end |
protected long |
m_start |
protected List<XmlSuite> |
m_suites |
protected boolean |
m_useDefaultListeners |
| Constructor and Description |
|---|
TestNG()
Default constructor.
|
TestNG(boolean useDefaultListeners)
Used by maven2 to have 0 output of any kind come out of testng.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addClassLoader(ClassLoader loader)
Add a class loader to the searchable loaders.
|
void |
addListener(ITestNGListener listener) |
void |
addListener(Object listener)
Deprecated.
Use addListener(ITestNGListener) instead
|
void |
addMethodSelector(String className,
int priority) |
void |
addMethodSelector(XmlMethodSelector selector) |
void |
alwaysRunListeners(boolean alwaysRun) |
protected void |
configure(CommandLineArgs cla)
Configure the TestNG instance based on the command line parameters.
|
void |
configure(Map cmdLineArgs)
Deprecated.
use new configure(CommandLineArgs) method
|
IAnnotationTransformer |
getAnnotationTransformer() |
XmlSuite.FailurePolicy |
getConfigFailurePolicy()
Returns the configuration failure policy.
|
protected IConfiguration |
getConfiguration() |
static TestNG |
getDefault()
Deprecated.
since 5.1
|
String |
getDefaultSuiteName() |
String |
getDefaultTestName() |
protected long |
getEnd() |
IExecutorFactory |
getExecutorFactory() |
String |
getOutputDirectory() |
boolean |
getReportAllDataDrivenTestsAsSkipped() |
Set<IReporter> |
getReporters() |
List<ITestNGListener> |
getServiceLoaderListeners() |
protected long |
getStart() |
int |
getStatus() |
List<ISuiteListener> |
getSuiteListeners() |
Integer |
getSuiteThreadPoolSize() |
List<ITestListener> |
getTestListeners() |
boolean |
hasFailure() |
boolean |
hasFailureWithinSuccessPercentage() |
boolean |
hasSkip() |
void |
initializeEverything()
Invoked by the remote runner.
|
void |
initializeSuitesAndJarFile() |
static void |
main(String[] argv)
The TestNG entry point for command line execution.
|
static TestNG |
privateMain(String[] argv,
ITestListener listener)
Note: this method is not part of the public API and is meant for internal usage only.
|
void |
run()
Run TestNG.
|
protected List<ISuite> |
runSuites()
Run the test suites.
|
List<ISuite> |
runSuitesLocally()
This needs to be public for maven2, for now..At least until an alternative mechanism is found.
|
void |
setCommandLineSuite(XmlSuite suite) |
void |
setConfigFailurePolicy(XmlSuite.FailurePolicy failurePolicy)
Sets the policy for whether or not to ever invoke a configuration method again after it has
failed once.
|
void |
setDataProviderThreadCount(int count) |
void |
setDefaultSuiteName(String defaultSuiteName) |
void |
setDefaultTestName(String defaultTestName) |
void |
setExcludedGroups(String groups)
Define which groups will be excluded from this run.
|
void |
setExecutorFactory(IExecutorFactory factory) |
void |
setExecutorFactoryClass(String clazzName) |
void |
setGroupByInstances(boolean b) |
void |
setGroups(String groups)
Define which groups will be included from this run.
|
void |
setInjectorFactory(IInjectorFactory factory) |
void |
setJUnit(Boolean isJUnit)
Specify if this run should be made in JUnit mode
|
void |
setListenerClasses(List<Class<? extends ITestNGListener>> classes)
Define which listeners to user for this run.
|
void |
setListenersToSkipFromBeingWiredInViaServiceLoaders(String... listeners) |
void |
setMethodInterceptor(IMethodInterceptor methodInterceptor) |
void |
setMixed(Boolean isMixed) |
void |
setObjectFactory(Class<? extends ITestObjectFactory> c) |
void |
setObjectFactory(ITestObjectFactory factory) |
void |
setOutputDirectory(String outputdir)
Sets the output directory where the reports will be created.
|
void |
setParallel(String parallel)
Deprecated.
Use #setParallel(XmlSuite.ParallelMode) instead
|
void |
setParallel(XmlSuite.ParallelMode parallel) |
void |
setPreserveOrder(boolean b) |
void |
setRandomizeSuites(boolean randomizeSuites) |
void |
setReportAllDataDrivenTestsAsSkipped(boolean reportAllDataDrivenTestsAsSkipped) |
void |
setServiceLoaderClassLoader(URLClassLoader ucl) |
void |
setSkipFailedInvocationCounts(Boolean skip) |
void |
setSourcePath(String path)
Deprecated.
|
void |
setSuiteThreadPoolSize(Integer suiteThreadPoolSize) |
void |
setTestClasses(Class[] classes)
Set the test classes to be run by this TestNG object.
|
void |
setTestJar(String jarPath)
Sets a jar containing a testng.xml file.
|
void |
setTestNames(List<String> testNames) |
protected void |
setTestRunnerFactory(ITestRunnerFactory itrf) |
void |
setTestSuites(List<String> suites)
Set the suites file names to be run by this TestNG object.
|
void |
setThreadCount(int threadCount) |
void |
setUseDefaultListeners(boolean useDefaultListeners) |
void |
setVerbose(int verbose)
Sets the level of verbosity.
|
void |
setXmlPathInJar(String xmlPathInJar) |
void |
setXmlSuites(List<XmlSuite> suites)
Specifies the XmlSuite objects to run.
|
void |
toggleFailureIfAllTestsWereSkipped(boolean failIfAllTestsSkipped) |
protected static void |
validateCommandLineParameters(CommandLineArgs args)
Double check that the command line parameters are valid.
|
public static final String DEFAULT_COMMAND_LINE_SUITE_NAME
public static final String DEFAULT_COMMAND_LINE_TEST_NAME
public static final String DEFAULT_OUTPUTDIR
protected boolean m_useDefaultListeners
public static final Integer DEFAULT_VERBOSE
protected long m_end
protected long m_start
public TestNG()
public TestNG(boolean useDefaultListeners)
useDefaultListeners - Whether or not any default reports should be added to tests.public void toggleFailureIfAllTestsWereSkipped(boolean failIfAllTestsSkipped)
failIfAllTestsSkipped - - 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).public void setListenersToSkipFromBeingWiredInViaServiceLoaders(String... listeners)
listeners - - An array of fully qualified class names that should be skipped from being
wired in via service loaders.public int getStatus()
public void setOutputDirectory(String outputdir)
outputdir - The directory.public void setUseDefaultListeners(boolean useDefaultListeners)
useDefaultListeners - If true before run(), the default listeners will not be used.
TestHTMLReporter,
JUnitXMLReporter,
XMLReporterpublic void setTestJar(String jarPath)
jarPath - - Path of the jarpublic void setXmlPathInJar(String xmlPathInJar)
xmlPathInJar - Sets the path to the XML file in the test jar file.public void initializeSuitesAndJarFile()
public void setThreadCount(int threadCount)
threadCount - Define the number of threads in the thread pool.@Deprecated public void setParallel(String parallel)
parallel - Define whether this run will be run in parallel mode.public void setParallel(XmlSuite.ParallelMode parallel)
public void setCommandLineSuite(XmlSuite suite)
public void setTestClasses(Class[] classes)
If used together with threadCount, parallel, groups, excludedGroups than this one must be set first.
classes - An array of classes that contain TestNG annotations.public void addMethodSelector(String className, int priority)
public void addMethodSelector(XmlMethodSelector selector)
public void setReportAllDataDrivenTestsAsSkipped(boolean reportAllDataDrivenTestsAsSkipped)
public boolean getReportAllDataDrivenTestsAsSkipped()
public void setTestSuites(List<String> suites)
suites - 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();
public void setExcludedGroups(String groups)
groups - A list of group names separated by a comma.public void setGroups(String groups)
groups - A list of group names separated by a comma.protected void setTestRunnerFactory(ITestRunnerFactory itrf)
public void setObjectFactory(Class<? extends ITestObjectFactory> c)
public void setObjectFactory(ITestObjectFactory factory)
public void setListenerClasses(List<Class<? extends ITestNGListener>> classes)
classes - A list of classes, which must be either ISuiteListener, ITestListener or
IReporter@Deprecated public void addListener(Object listener)
listener - The listener to addpublic void addListener(ITestNGListener listener)
public List<ITestListener> getTestListeners()
public List<ISuiteListener> getSuiteListeners()
public void setVerbose(int verbose)
verbose - 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).public void setExecutorFactoryClass(String clazzName)
public void setExecutorFactory(IExecutorFactory factory)
public IExecutorFactory getExecutorFactory()
public void initializeEverything()
public void run()
protected List<ISuite> runSuites()
This method can be overridden by subclass.
For example, DistributedTestNG to run in master/slave mode according to commandline args.
ISuite objects.public List<ISuite> runSuitesLocally()
protected IConfiguration getConfiguration()
public static void main(String[] argv)
argv - the TestNG command line parameters.public static TestNG privateMain(String[] argv, ITestListener listener)
argv - The param argumentslistener - The listenerprotected void configure(CommandLineArgs cla)
cla - The command line parameterspublic void setSuiteThreadPoolSize(Integer suiteThreadPoolSize)
public Integer getSuiteThreadPoolSize()
public void setRandomizeSuites(boolean randomizeSuites)
public void alwaysRunListeners(boolean alwaysRun)
@Deprecated public void setSourcePath(String path)
path - The path@Deprecated public void configure(Map cmdLineArgs)
cmdLineArgs - The command linepublic void setTestNames(List<String> testNames)
testNames - Only run the specified tests from the suite.public void setSkipFailedInvocationCounts(Boolean skip)
public void setJUnit(Boolean isJUnit)
isJUnit - - Specify if this run should be made in JUnit modepublic void setMixed(Boolean isMixed)
isMixed - Specify if this run should be made in mixed modeprotected static void validateCommandLineParameters(CommandLineArgs args)
args - The command line to checkpublic boolean hasFailure()
public boolean hasFailureWithinSuccessPercentage()
public boolean hasSkip()
public String getOutputDirectory()
public IAnnotationTransformer getAnnotationTransformer()
public String getDefaultSuiteName()
public void setDefaultSuiteName(String defaultSuiteName)
defaultSuiteName - the defaultSuiteName to setpublic String getDefaultTestName()
public void setDefaultTestName(String defaultTestName)
defaultTestName - the defaultTestName to setpublic void setConfigFailurePolicy(XmlSuite.FailurePolicy failurePolicy)
XmlSuite. The default value is XmlSuite.FailurePolicy.SKIPfailurePolicy - the configuration failure policypublic XmlSuite.FailurePolicy getConfigFailurePolicy()
@Deprecated public static TestNG getDefault()
public void setMethodInterceptor(IMethodInterceptor methodInterceptor)
public void setDataProviderThreadCount(int count)
public void addClassLoader(ClassLoader loader)
loader - The class loader to addpublic void setPreserveOrder(boolean b)
protected long getStart()
protected long getEnd()
public void setGroupByInstances(boolean b)
public void setServiceLoaderClassLoader(URLClassLoader ucl)
public List<ITestNGListener> getServiceLoaderListeners()
public void setInjectorFactory(IInjectorFactory factory)
Copyright © 2025. All rights reserved.