org.testng
Class TestNG

java.lang.Object  extended by org.testng.TestNG
Direct Known Subclasses:
RemoteTestNG, TestNG

public class TestNG
extends Object

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:

  • On an existing testng.xml
  • On a synthetic testng.xml, created entirely from Java
  • By directly setting the test classes
You can also define which groups to include or exclude, assign parameters, etc...

The command line parameters are:

  • -d outputdir: specify the output directory
  • -testclass class_name: specifies one or several class names
  • -testjar jar_name: specifies the jar containing the tests
  • -sourcedir src1;src2: ; separated list of source directories (used only when javadoc annotations are used)
  • -target
  • -groups
  • -testrunfactory
  • -listener

Please consult documentation for more details. FIXME: should support more than simple paths for suite xmls

Author:
Cedric Beust, Alex Popescu
See Also:
usage()


Nested Class Summary
static classTestNG.ExitCodeListener
           
 
Field Summary
static StringDEFAULT_COMMAND_LINE_SUITE_NAME
          The default name for a suite launched from the command line
static StringDEFAULT_COMMAND_LINE_TEST_NAME
          The default name for a test launched from the command line
static StringDEFAULT_OUTPUTDIR
          The default name of the result's output directory (keep public, used by Eclipse).
static IntegerDEFAULT_VERBOSE
           
protected static intHAS_FAILURE
           
protected static intHAS_FSP
           
protected static intHAS_NO_TEST
           
protected static intHAS_SKIPPED
           
protected  longm_end
           
protected  longm_start
           
protected  List<XmlSuite>m_suites
           
protected  booleanm_useDefaultListeners
           
static StringSHOW_TESTNG_STACK_FRAMES
          System properties
static StringTEST_CLASSPATH
           
 
Constructor Summary
TestNG()
          Default constructor.
TestNG(boolean useDefaultListeners)
          Used by maven2 to have 0 output of any kind come out of testng.
 
Method Summary
 voidaddClassLoader(ClassLoader loader)
          Add a class loader to the searchable loaders.
 voidaddExecutionListener(IExecutionListener l)
           
 voidaddInvokedMethodListener(IInvokedMethodListener listener)
           
 voidaddListener(IInvokedMethodListener listener)
           
 voidaddListener(IReporter listener)
           
 voidaddListener(ISuiteListener listener)
           
 voidaddListener(ITestListener listener)
           
 voidaddListener(Object listener)
           
 voidaddMethodSelector(String className, int priority)
           
protected  voidconfigure(CommandLineArgs cla)
          Configure the TestNG instance based on the command line parameters.
 voidconfigure(Map cmdLineArgs)
          Deprecated. use new configure(CommandLineArgs) method
 IAnnotationTransformergetAnnotationTransformer()
           
 StringgetConfigFailurePolicy()
          Returns the configuration failure policy.
protected  org.testng.internal.IConfigurationgetConfiguration()
           
static TestNGgetDefault()
          Deprecated. since 5.1
 StringgetDefaultSuiteName()
           
 StringgetDefaultTestName()
           
protected  longgetEnd()
           
 StringgetOutputDirectory()
           
 Set<IReporter>getReporters()
           
 List<ITestNGListener>getServiceLoaderListeners()
           
protected  longgetStart()
           
 intgetStatus()
           
 List<ISuiteListener>getSuiteListeners()
           
 IntegergetSuiteThreadPoolSize()
           
 List<ITestListener>getTestListeners()
           
 booleanhasFailure()
           
 booleanhasFailureWithinSuccessPercentage()
           
 booleanhasSkip()
           
 voidinitializeSuitesAndJarFile()
           
static booleanisJdk14()
          Deprecated. 
static voidmain(String[] argv)
          The TestNG entry point for command line execution.
static TestNGprivateMain(String[] argv, ITestListener listener)
          Note: this method is not part of the public API and is meant for internal usage only.
 voidrun()
          Run TestNG.
 List<ISuite>runSuitesLocally()
          This needs to be public for maven2, for now..At least until an alternative mechanism is found.
 voidsetAnnotationTransformer(IAnnotationTransformer t)
           
 voidsetCommandLineSuite(XmlSuite suite)
           
 voidsetConfigFailurePolicy(String failurePolicy)
          Sets the policy for whether or not to ever invoke a configuration method again after it has failed once.
 voidsetDataProviderThreadCount(int count)
           
 voidsetDefaultSuiteName(String defaultSuiteName)
           
 voidsetDefaultTestName(String defaultTestName)
           
 voidsetExcludedGroups(String groups)
          Define which groups will be excluded from this run.
 voidsetGroupByInstances(boolean b)
           
 voidsetGroups(String groups)
          Define which groups will be included from this run.
 voidsetHasFailure(boolean hasFailure)
          Deprecated. since 5.1
 voidsetHasFailureWithinSuccessPercentage(boolean hasFailureWithinSuccessPercentage)
          Deprecated. since 5.1
 voidsetHasSkip(boolean hasSkip)
          Deprecated. since 5.1
 voidsetJUnit(Boolean isJUnit)
          Specify if this run should be made in JUnit mode
 voidsetListenerClasses(List<Class> classes)
          Define which listeners to user for this run.
 voidsetMaster(String fileName)
          Specify if this run should be in Master-Slave mode as Master
 voidsetMethodInterceptor(IMethodInterceptor i)
           
 voidsetMixed(Boolean isMixed)
          Specify if this run should be made in mixed mode
 voidsetObjectFactory(Class c)
           
 voidsetObjectFactory(ITestObjectFactory factory)
           
 voidsetOutputDirectory(String outputdir)
          Sets the output directory where the reports will be created.
 voidsetParallel(String parallel)
          Define whether this run will be run in parallel mode.
 voidsetPreserveOrder(boolean b)
           
 voidsetRandomizeSuites(boolean randomizeSuites)
           
 voidsetServiceLoaderClassLoader(URLClassLoader ucl)
           
 voidsetSkipFailedInvocationCounts(Boolean skip)
           
 voidsetSlave(String fileName)
          Specify if this run should be in Master-Slave mode as slave
 voidsetSourcePath(String path)
          This method is invoked by Maven's Surefire, only remove it once Surefire has been modified to no longer call it.
 voidsetSuiteThreadPoolSize(Integer suiteThreadPoolSize)
           
 voidsetTestClasses(Class[] classes)
          Set the test classes to be run by this TestNG object.
 voidsetTestJar(String jarPath)
          Sets a jar containing a testng.xml file.
 voidsetTestNames(List<String> testNames)
          Only run the specified tests from the suite.
static voidsetTestNGVersion()
          Deprecated. The TestNG version is now established at load time. This method is not required anymore and is now a no-op.
protected  voidsetTestRunnerFactory(ITestRunnerFactory itrf)
           
 voidsetTestSuites(List<String> suites)
          Set the suites file names to be run by this TestNG object.
 voidsetThreadCount(int threadCount)
          Define the number of threads in the thread pool.
 voidsetUseDefaultListeners(boolean useDefaultListeners)
          If this method is passed true before run(), the default listeners will not be used.
 voidsetVerbose(int verbose)
          Sets the level of verbosity.
 voidsetXmlPathInJar(String xmlPathInJar)
          Sets the path to the XML file in the test jar file.
 voidsetXmlSuites(List<XmlSuite> suites)
          Specifies the XmlSuite objects to run.
protected static voidvalidateCommandLineParameters(CommandLineArgs args)
          Double check that the command line parameters are valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMMAND_LINE_SUITE_NAME

public static final String DEFAULT_COMMAND_LINE_SUITE_NAME
The default name for a suite launched from the command line

See Also:
Constant Field Values


DEFAULT_COMMAND_LINE_TEST_NAME

public static final String DEFAULT_COMMAND_LINE_TEST_NAME
The default name for a test launched from the command line

See Also:
Constant Field Values


DEFAULT_OUTPUTDIR

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

See Also:
Constant Field Values


SHOW_TESTNG_STACK_FRAMES

public static final String SHOW_TESTNG_STACK_FRAMES
System properties

See Also:
Constant Field Values


TEST_CLASSPATH

public static final String TEST_CLASSPATH
See Also:
Constant Field Values

m_suites

protected List<XmlSuite> m_suites

m_useDefaultListeners

protected boolean m_useDefaultListeners

HAS_FAILURE

protected static final int HAS_FAILURE
See Also:
Constant Field Values

HAS_SKIPPED

protected static final int HAS_SKIPPED
See Also:
Constant Field Values

HAS_FSP

protected static final int HAS_FSP
See Also:
Constant Field Values

HAS_NO_TEST

protected static final int HAS_NO_TEST
See Also:
Constant Field Values

DEFAULT_VERBOSE

public static final Integer DEFAULT_VERBOSE

m_end

protected long m_end

m_start

protected long m_start
Constructor Detail

TestNG

public TestNG()
Default constructor. Setting also usage of default listeners/reporters.


TestNG

public TestNG(boolean useDefaultListeners)
Used by maven2 to have 0 output of any kind come out of testng.

Parameters:
useDefaultListeners - Whether or not any default reports should be added to tests.

Method Detail

getStatus

public int getStatus()

setOutputDirectory

public void setOutputDirectory(String outputdir)
Sets the output directory where the reports will be created.

Parameters:
outputdir - The directory.

setUseDefaultListeners

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

See Also:
TestHTMLReporter, JUnitXMLReporter, XMLReporter

setTestJar

public void setTestJar(String jarPath)
Sets a jar containing a testng.xml file.

Parameters:
jarPath -

setXmlPathInJar

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


initializeSuitesAndJarFile

public void initializeSuitesAndJarFile()

setThreadCount

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


setParallel

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


setCommandLineSuite

public void setCommandLineSuite(XmlSuite suite)

setTestClasses

public void setTestClasses(Class[] classes)
Set the test classes to be run by this TestNG object. This method will create a dummy suite that will wrap these classes called "Command Line Test".

If used together with threadCount, parallel, groups, excludedGroups than this one must be set first.

Parameters:
classes - An array of classes that contain TestNG annotations.

addMethodSelector

public void addMethodSelector(String className,                              int priority)

setTestSuites

public void setTestSuites(List<String> suites)
Set the suites file names to be run by this TestNG object. This method tries to load and parse the specified TestNG suite xml files. If a file is missing, it is ignored.

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

setXmlSuites

public void setXmlSuites(List<XmlSuite> suites)
Specifies the XmlSuite objects to run.

Parameters:
suites -
See Also:
XmlSuite

setExcludedGroups

public void setExcludedGroups(String groups)
Define which groups will be excluded from this run.

Parameters:
groups - A list of group names separated by a comma.

setGroups

public void setGroups(String groups)
Define which groups will be included from this run.

Parameters:
groups - A list of group names separated by a comma.

setTestRunnerFactory

protected void setTestRunnerFactory(ITestRunnerFactory itrf)

setObjectFactory

public void setObjectFactory(Class c)

setObjectFactory

public void setObjectFactory(ITestObjectFactory factory)

setListenerClasses

public void setListenerClasses(List<Class> classes)
Define which listeners to user for this run.

Parameters:
classes - A list of classes, which must be either ISuiteListener, ITestListener or IReporter

addListener

public void addListener(Object listener)

addListener

public void addListener(IInvokedMethodListener listener)

addListener

public void addListener(ISuiteListener listener)

addListener

public void addListener(ITestListener listener)

addListener

public void addListener(IReporter listener)

addInvokedMethodListener

public void addInvokedMethodListener(IInvokedMethodListener listener)

getReporters

public Set<IReporter> getReporters()

getTestListeners

public List<ITestListener> getTestListeners()

getSuiteListeners

public List<ISuiteListener> getSuiteListeners()

setVerbose

public void setVerbose(int verbose)
Sets the level of verbosity. This value will override the value specified in the test suites.

Parameters:
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).

run

public void run()
Run TestNG.


addExecutionListener

public void addExecutionListener(IExecutionListener l)

runSuitesLocally

public List<ISuite> runSuitesLocally()
This needs to be public for maven2, for now..At least until an alternative mechanism is found.


getConfiguration

protected org.testng.internal.IConfiguration getConfiguration()

main

public static void main(String[] argv)
The TestNG entry point for command line execution.

Parameters:
argv - the TestNG command line parameters.
Throws:
FileNotFoundException

privateMain

public static TestNG privateMain(String[] argv,                                 ITestListener listener)
Note: this method is not part of the public API and is meant for internal usage only.


configure

protected void configure(CommandLineArgs cla)
Configure the TestNG instance based on the command line parameters.


setSuiteThreadPoolSize

public void setSuiteThreadPoolSize(Integer suiteThreadPoolSize)

getSuiteThreadPoolSize

public Integer getSuiteThreadPoolSize()

setRandomizeSuites

public void setRandomizeSuites(boolean randomizeSuites)

setSourcePath

public void setSourcePath(String path)
This method is invoked by Maven's Surefire, only remove it once Surefire has been modified to no longer call it.


configure

@Deprecatedpublic void configure(Map 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.


setTestNames

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


setSkipFailedInvocationCounts

public void setSkipFailedInvocationCounts(Boolean skip)

setMaster

public void setMaster(String fileName)
Specify if this run should be in Master-Slave mode as Master

Parameters:
fileName - remote.properties path

setSlave

public void setSlave(String fileName)
Specify if this run should be in Master-Slave mode as slave

Parameters:
fileName - remote.properties path

setJUnit

public void setJUnit(Boolean isJUnit)
Specify if this run should be made in JUnit mode

Parameters:
isJUnit -

setMixed

public void setMixed(Boolean isMixed)
Specify if this run should be made in mixed mode


setTestNGVersion

@Deprecatedpublic static void setTestNGVersion()
Deprecated. The TestNG version is now established at load time. This method is not required anymore and is now a no-op.


isJdk14

@Deprecatedpublic static boolean isJdk14()
Deprecated. 

Returns true if this is the JDK 1.4 JAR version of TestNG, false otherwise.

Returns:
true if this is the JDK 1.4 JAR version of TestNG, false otherwise.

validateCommandLineParameters

protected static void validateCommandLineParameters(CommandLineArgs args)
Double check that the command line parameters are valid.


hasFailure

public boolean hasFailure()
Returns:
true if at least one test failed.

hasFailureWithinSuccessPercentage

public boolean hasFailureWithinSuccessPercentage()
Returns:
true if at least one test failed within success percentage.

hasSkip

public boolean hasSkip()
Returns:
true if at least one test was skipped.

getOutputDirectory

public String getOutputDirectory()

getAnnotationTransformer

public IAnnotationTransformer getAnnotationTransformer()

setAnnotationTransformer

public void setAnnotationTransformer(IAnnotationTransformer t)

getDefaultSuiteName

public String getDefaultSuiteName()
Returns:
the defaultSuiteName

setDefaultSuiteName

public void setDefaultSuiteName(String defaultSuiteName)
Parameters:
defaultSuiteName - the defaultSuiteName to set

getDefaultTestName

public String getDefaultTestName()
Returns:
the defaultTestName

setDefaultTestName

public void setDefaultTestName(String defaultTestName)
Parameters:
defaultTestName - the defaultTestName to set

setConfigFailurePolicy

public void setConfigFailurePolicy(String failurePolicy)
Sets the policy for whether or not to ever invoke a configuration method again after it has failed once. Possible values are defined in XmlSuite. The default value is XmlSuite.SKIP.

Parameters:
failurePolicy - the configuration failure policy

getConfigFailurePolicy

public String getConfigFailurePolicy()
Returns the configuration failure policy.

Returns:
config failure policy

getDefault

@Deprecatedpublic static TestNG getDefault()
Deprecated. since 5.1


setHasFailure

@Deprecatedpublic void setHasFailure(boolean hasFailure)
Deprecated. since 5.1


setHasFailureWithinSuccessPercentage

@Deprecatedpublic void setHasFailureWithinSuccessPercentage(boolean hasFailureWithinSuccessPercentage)
Deprecated. since 5.1


setHasSkip

@Deprecatedpublic void setHasSkip(boolean hasSkip)
Deprecated. since 5.1


setMethodInterceptor

public void setMethodInterceptor(IMethodInterceptor i)

setDataProviderThreadCount

public void setDataProviderThreadCount(int count)

addClassLoader

public void addClassLoader(ClassLoader loader)
Add a class loader to the searchable loaders.


setPreserveOrder

public void setPreserveOrder(boolean b)

getStart

protected long getStart()

getEnd

protected long getEnd()

setGroupByInstances

public void setGroupByInstances(boolean b)

setServiceLoaderClassLoader

public void setServiceLoaderClassLoader(URLClassLoader ucl)

getServiceLoaderListeners

public List<ITestNGListener> getServiceLoaderListeners()


Copyright © 2012. All Rights Reserved.


NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14