Package guru.mikelue.jdut.testng
Class IInvokedMethodYamlFactoryListener
- java.lang.Object
-
- guru.mikelue.jdut.testng.YamlFactoryListenerBase
-
- guru.mikelue.jdut.testng.IInvokedMethodYamlFactoryListener
-
- All Implemented Interfaces:
IInvokedMethodListener
,ITestNGListener
public class IInvokedMethodYamlFactoryListener extends YamlFactoryListenerBase implements IInvokedMethodListener
This listener uses conventions of file name by (classpath:<package>/<class_name>-<method_name>.yaml
) for conducting data.Only testing method which is annotated
@JdutResource
would be prepared for data conduction.By default, the
DataSource
would be retrieved fromITestContext
object(which type ofIAttributes
).By value of
TestNGConfig.oneTimeOnly()
, this listener would executes only one time or multiple times for testing method with data provider.Example by defulat conventions:
package guru.mikelue.jdut.testng.example; @Test(testName="ReefSharkTest") @Listeners(IInvokedMethodYamlFactoryListener.class) public class ReefSharkTest { // Puts data source into test context @BeforeTest protected static void putDataSourceTest(ITestContext testContext) { YamlFactoryListenerBase.setDataSource(testContext, getDataSource()); } // Removes data source from test context @AfterTest protected static void pullDataSourceTest(ITestContext testContext) { YamlFactoryListenerBase.removeDataSource(testContext); } // File: guru/mikelue/jdut/testng/example // -> ReefSharkTest-traceVictim.yaml @Test @JdutResource public void traceVictim() { } // File: guru/mikelue/jdut/testng/example // -> ReefSharkTest-bite.yaml @Test(dataProvider="bite") @TestNGConfig(oneTimeOnly=true) @JdutResource public void bite(int speed) { // Executes tested code // Assertions ... } @DataProvider Object[][] bite() { return new Object[][] { { 0 }, { 30 }, { 2000 }, }; } }
You can override
YamlFactoryListenerBase.buildYamlConductorFactory(org.testng.IAttributes)
to customize the object ofDataSource
.
-
-
Constructor Summary
Constructors Constructor Description IInvokedMethodYamlFactoryListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterInvocation(IInvokedMethod method, ITestResult testResult)
ExecutesduetConductorBuild
if and only ifbeforeInvocation(org.testng.IInvokedMethod,org.testng.ITestResult)
has set-up a conductor.
Configuration methods won't be applied by this listener.void
beforeInvocation(IInvokedMethod method, ITestResult testResult)
ExecutesduetConductorBuild
if and only if the will-be invoked method is test one.
Configuration methods won't be applied by this listener.protected Optional<DuetConductor>
buildDuetConductor(IAttributes attributes)
Builds the conductor from data sourceITestResult.getTestContext()
of attributes(asITestResult
).
This method would build conductor only for testing method withJdutResource
annotation.protected boolean
needConductData(IInvokedMethod method, ITestResult testResult)
Checks whether or not the context should make.
By default, this method always returns true.-
Methods inherited from class guru.mikelue.jdut.testng.YamlFactoryListenerBase
buildYamlConductorFactory, duetConductorBuild, duetConductorClean, getDataSource, getLogger, removeDataSource, setDataSource
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.testng.IInvokedMethodListener
afterInvocation, beforeInvocation
-
-
-
-
Method Detail
-
beforeInvocation
public void beforeInvocation(IInvokedMethod method, ITestResult testResult)
ExecutesduetConductorBuild
if and only if the will-be invoked method is test one.
Configuration methods won't be applied by this listener.- Specified by:
beforeInvocation
in interfaceIInvokedMethodListener
- Parameters:
method
- The method provided by TestNG frameworktestResult
- The result object provided byh TestNG framework
-
afterInvocation
public void afterInvocation(IInvokedMethod method, ITestResult testResult)
ExecutesduetConductorBuild
if and only ifbeforeInvocation(org.testng.IInvokedMethod,org.testng.ITestResult)
has set-up a conductor.
Configuration methods won't be applied by this listener.- Specified by:
afterInvocation
in interfaceIInvokedMethodListener
- Parameters:
method
- The method provided by TestNG frameworktestResult
- The result object provided byh TestNG framework
-
buildDuetConductor
protected Optional<DuetConductor> buildDuetConductor(IAttributes attributes)
Builds the conductor from data sourceITestResult.getTestContext()
of attributes(asITestResult
).
This method would build conductor only for testing method withJdutResource
annotation.- Specified by:
buildDuetConductor
in classYamlFactoryListenerBase
- Parameters:
attributes
- The object ofITestResult
- Returns:
- The initialized conductor or nothing
-
needConductData
protected boolean needConductData(IInvokedMethod method, ITestResult testResult)
Checks whether or not the context should make.
By default, this method always returns true.- Parameters:
method
- The method provided by TestNG frameworktestResult
- The result object provided byh TestNG framework- Returns:
- true if this context should apply data conduction
-
-