Package org.testng
Class TestRunner
java.lang.Object
org.testng.TestRunner
- All Implemented Interfaces:
IAttributes,IConfigEavesdropper,ITestResultNotifier,ITestContext,IThreadWorkerFactory<ITestNGMethod>
public class TestRunner
extends Object
implements ITestContext, ITestResultNotifier, IThreadWorkerFactory<ITestNGMethod>, IConfigEavesdropper
This class takes care of running one Test.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Comparator<ITestNGMethod> private static final Stringprivate ITestListenerprivate final DataProviderHolderprivate static final Loggerprivate ITestNGMethod[]private ITestNGMethod[]private ITestNGMethod[]private IAnnotationFinderprivate final IAttributesprivate ITestNGMethod[]private ITestNGMethod[]private final Map<Class<? extends IClassListener>, IClassListener> private final Map<Class<?>, ITestClass> A map to keep track of Class invalid input: '<'-> IClass.private ClassMethodMapprivate final IResultMapprivate IConfigurationprivate final Set<IConfigurationListener> private final IConfigurationListenerprivate Dateprivate final List<ITestNGMethod> private final IResultMapprivate final IResultMapprivate final IResultMapprivate ConfigurationGroupMethodsprivate Stringprivate IInjectorFactoryprivate Collection<IInvokedMethodListener> private IInvokerprivate List<IMethodInterceptor> private ITestObjectFactoryprivate StringWhere the reports will be created.private final IResultMapprivate final IResultMapprivate final RunInfoprivate final IResultMapprivate final IResultMapprivate Dateprivate ISuiteprivate TestNGClassFinderprivate final List<ITestListener> ITestListeners support.private Stringprivate final XmlMethodSelectorprivate XmlTestprivate final IContainer<ITestNGMethod> private final Set<IExecutionVisualiser> private static final AtomicBoolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionTestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator, SuiteRunner suiteRunner) TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, SuiteRunner suiteRunner) protectedTestRunner(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator, DataProviderHolder otherHolder, SuiteRunner suiteRunner) -
Method Summary
Modifier and TypeMethodDescription(package private) voidvoidaddFailedButWithinSuccessPercentageTest(ITestNGMethod testMethod, ITestResult result) voidaddFailedTest(ITestNGMethod testMethod, ITestResult result) voidaddListener(ITestNGListener listener) private voidaddMetaGroup(String name, List<String> groupNames) (package private) voidaddMethodInterceptor(IMethodInterceptor methodInterceptor) voidaddPassedTest(ITestNGMethod tm, ITestResult tr) voidaddSkippedTest(ITestNGMethod tm, ITestResult tr) (package private) voidaddTestListener(ITestListener listener) private voidafterRun()private voidBefore run preparements.private ITestNGMethod[]createGroups(List<String> groups) createWorkers(List<ITestNGMethod> methods) Create a list of workers to run the methods passed in parameter.private voidprivate voidfireEvent(boolean isStart) Trigger the start/finish event.private voidprivate List<XmlPackage> Returns all packages to use for the current test.getAttribute(String name) String[]getHost()String[]getName()getSuite()getTest()static intprivate voidinit()private voidinit(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder annotationFinder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, SuiteRunner suiteRunner) private voidprivate voidinitMetaGroups(XmlTest xmlTest) Initialize meta groupsprivate voidprivate voidinitRunInfo(XmlTest xmlTest) private ITestNGMethod[]intercept(ITestNGMethod[] methods) Apply the method interceptor (if applicable) to the list of methods.private voidinvokeTestConfigurations(ITestNGMethod[] testConfigurationMethods) private static voidprivate voidlogFailedTest(ITestResult tr, boolean withinSuccessPercentage) private voidlogStart()Logs the beginning of thebeforeRun().methods(Stream<ITestNGMethod> methods) methods(IResultMap resultMap) private static Comparator<ITestNGMethod> newComparator(boolean needPrioritySort) private static BlockingQueue<Runnable> newQueue(boolean needPrioritySort) private voidprivateRun(XmlTest xmlTest) Main method that create a graph of methods and then pass it to the graph executor to run them.private voidremoveAttribute(String name) Remove the attributevoidrun()The main entry method for TestRunner.private voidrunJUnitWorkers(List<? extends IWorker<ITestNGMethod>> workers) voidsetAttribute(String name, Object value) Set a custom attribute.private voidsetExitCodeListener(ITestListener exitCodeListener) voidvoidsetTestName(String name) voidsetVerbose(int n) private booleansortOnPriority(ITestNGMethod[] interceptedOrder)
-
Field Details
-
DEFAULT_PROP_OUTPUT_DIR
- See Also:
-
LOGGER
-
comparator
-
m_suite
-
m_xmlTest
-
m_testName
-
m_injectorFactory
-
m_objectFactory
-
m_testClassesFromXml
-
m_invoker
-
m_annotationFinder
-
m_testListeners
ITestListeners support. -
m_configurationListeners
-
visualisers
-
m_confListener
-
m_invokedMethodListeners
-
m_classListeners
-
holder
-
m_startDate
-
m_endDate
-
testMethodsContainer
-
m_classMap
A map to keep track of Class invalid input: '<'-> IClass. -
m_outputDirectory
Where the reports will be created. -
m_xmlMethodSelector
-
exitCodeListener
-
m_beforeSuiteMethods
-
m_afterSuiteMethods
-
m_beforeXmlTestMethods
-
m_afterXmlTestMethods
-
m_excludedMethods
-
m_groupMethods
-
m_metaGroups
-
m_passedTests
-
m_failedTests
-
m_failedButWithinSuccessPercentageTests
-
m_skippedTests
-
m_runInfo
-
m_host
-
m_methodInterceptors
-
m_classMethodMap
-
m_testClassFinder
-
m_configuration
-
m_allJunitTestMethods
-
warnOnce
-
m_passedConfigurations
-
m_skippedConfigurations
-
m_failedConfigurations
-
m_configsToBeInvoked
-
m_attributes
-
-
Constructor Details
-
TestRunner
protected TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator, DataProviderHolder otherHolder, SuiteRunner suiteRunner) -
TestRunner
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator, SuiteRunner suiteRunner) -
TestRunner
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, SuiteRunner suiteRunner)
-
-
Method Details
-
init
private void init(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder annotationFinder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, SuiteRunner suiteRunner) -
getAllPackages
Returns all packages to use for the current test. This includes the test from the test suite. Never returns null. -
getInvoker
-
getBeforeSuiteMethods
-
getAfterSuiteMethods
-
getBeforeTestConfigurationMethods
-
getAfterTestConfigurationMethods
-
init
private void init() -
initListeners
private void initListeners() -
initMetaGroups
Initialize meta groups -
initRunInfo
-
initMethods
private void initMethods() -
computeAndGetAllTestMethods
-
getTestClasses
-
setTestName
-
setOutputDirectory
-
addMetaGroup
-
createGroups
-
run
public void run()The main entry method for TestRunner.This is where all the hard work is done: - Invoke configuration methods - Invoke test methods - Catch exceptions - Collect results - Invoke listeners - etc...
-
forgetHeavyReferencesIfNeeded
private void forgetHeavyReferencesIfNeeded() -
beforeRun
private void beforeRun()Before run preparements. -
invokeTestConfigurations
-
privateRunJUnit
private void privateRunJUnit() -
newComparator
-
sortOnPriority
-
newQueue
-
privateRun
Main method that create a graph of methods and then pass it to the graph executor to run them. -
intercept
Apply the method interceptor (if applicable) to the list of methods. -
createWorkers
Create a list of workers to run the methods passed in parameter. Each test method is run in its own worker except in the following cases: - The method belongs to a class that has @Test(sequential=true) - The parallel attribute is set to "classes" In both these cases, all the methods belonging to that class will then be put in the same worker in order to run in the same thread.- Specified by:
createWorkersin interfaceIThreadWorkerFactory<ITestNGMethod>- Parameters:
methods- tasks that need to be executed- Returns:
- list of workers
-
runJUnitWorkers
-
afterRun
private void afterRun() -
logStart
private void logStart()Logs the beginning of thebeforeRun(). -
fireEvent
private void fireEvent(boolean isStart) Trigger the start/finish event.- Parameters:
isStart- true if the event is for start, false if the event is for finish
-
methods
-
methods
-
getName
- Specified by:
getNamein interfaceITestContext- Returns:
- The name of this test.
-
getStartDate
- Specified by:
getStartDatein interfaceITestContext- Returns:
- Returns the startDate.
-
getEndDate
- Specified by:
getEndDatein interfaceITestContext- Returns:
- Returns the endDate.
-
getPassedTests
- Specified by:
getPassedTestsin interfaceITestContext- Returns:
- A list of all the tests that run successfully.
-
getSkippedTests
- Specified by:
getSkippedTestsin interfaceITestContext- Returns:
- A list of all the tests that were skipped
-
getFailedTests
- Specified by:
getFailedTestsin interfaceITestContext- Returns:
- A map of all the tests that failed, indexed by their ITestNGMethod.
- See Also:
-
getFailedButWithinSuccessPercentageTests
- Specified by:
getFailedButWithinSuccessPercentageTestsin interfaceITestContext- Returns:
- A list of all the tests that failed but are being ignored because annotated with a successPercentage.
-
getIncludedGroups
- Specified by:
getIncludedGroupsin interfaceITestContext- Returns:
- All the groups that are included for this test run.
-
getExcludedGroups
- Specified by:
getExcludedGroupsin interfaceITestContext- Returns:
- All the groups that are excluded for this test run.
-
getOutputDirectory
- Specified by:
getOutputDirectoryin interfaceITestContext- Returns:
- Where the reports will be generated.
-
getSuite
- Specified by:
getSuitein interfaceITestContext- Returns:
- Returns the suite.
-
getAllTestMethods
- Specified by:
getAllTestMethodsin interfaceITestContext- Returns:
- All the test methods that were run.
-
getHost
- Specified by:
getHostin interfaceITestContext- Returns:
- The host where this test was run, or null if it was run locally. The returned string has the form: host:port
-
getExcludedMethods
- Specified by:
getExcludedMethodsin interfaceITestContext- Returns:
- All the methods that were not included in this test run.
-
getFailedConfigurations
- Specified by:
getFailedConfigurationsin interfaceITestContext- Returns:
- The information about the failed configuration method invocations.
- See Also:
-
getConfigurationsScheduledForInvocation
- Specified by:
getConfigurationsScheduledForInvocationin interfaceIConfigEavesdropper
-
getPassedConfigurations
- Specified by:
getPassedConfigurationsin interfaceITestContext- Returns:
- The information about the successful configuration method invocations.
- See Also:
-
getSkippedConfigurations
- Specified by:
getSkippedConfigurationsin interfaceITestContext- Returns:
- The information about the skipped configuration method invocations.
- See Also:
-
addPassedTest
- Specified by:
addPassedTestin interfaceITestResultNotifier
-
getPassedTests
- Specified by:
getPassedTestsin interfaceITestResultNotifier
-
getFailedTests
- Specified by:
getFailedTestsin interfaceITestResultNotifier
-
getSkippedTests
- Specified by:
getSkippedTestsin interfaceITestResultNotifier
-
addSkippedTest
- Specified by:
addSkippedTestin interfaceITestResultNotifier
-
addFailedTest
- Specified by:
addFailedTestin interfaceITestResultNotifier
-
addFailedButWithinSuccessPercentageTest
- Specified by:
addFailedButWithinSuccessPercentageTestin interfaceITestResultNotifier
-
getTest
- Specified by:
getTestin interfaceITestResultNotifier
-
getTestListeners
- Specified by:
getTestListenersin interfaceITestResultNotifier
-
getConfigurationListeners
- Specified by:
getConfigurationListenersin interfaceITestResultNotifier
-
logFailedTest
-
log
-
getVerbose
public static int getVerbose() -
setVerbose
public void setVerbose(int n) -
addTestListener
-
addListener
-
addConfigurationListener
-
setExitCodeListener
-
getExitCodeListener
- Specified by:
getExitCodeListenerin interfaceITestResultNotifier
-
dumpInvokedMethods
private void dumpInvokedMethods() -
addMethodInterceptor
-
getCurrentXmlTest
- Specified by:
getCurrentXmlTestin interfaceITestContext- Returns:
- the current XmlTest.
-
getAttribute
- Specified by:
getAttributein interfaceIAttributes- Parameters:
name- The name of the attribute to return- Returns:
- The attribute
-
setAttribute
Description copied from interface:IAttributesSet a custom attribute.- Specified by:
setAttributein interfaceIAttributes- Parameters:
name- The attribute namevalue- The attribute value
-
getAttributeNames
- Specified by:
getAttributeNamesin interfaceIAttributes- Returns:
- all the attributes names.
-
removeAttribute
Description copied from interface:IAttributesRemove the attribute- Specified by:
removeAttributein interfaceIAttributes- Parameters:
name- The attribute name- Returns:
- the attribute value if found, null otherwise
-
getInjectorFactory
- Specified by:
getInjectorFactoryin interfaceITestContext
-