testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.99k stars 1.02k forks source link

IAnnotationTransformer listener changes the annotations only once per execution instead of before each BeforeSuite #1469

Open vitanivanov opened 7 years ago

vitanivanov commented 7 years ago

TestNG Version

Latest

Expected behavior

IAnnotationTransfomer listener changes the annotations after each "BeforeSuite" event is received.

Actual behavior

IAnnotationTransformer listener changes the annotations only once.

Is the issue reproductible on runner?

Test case sample

I have the following factory:

@Factory(dataProvider = "databaseProvider")
public Object[] executeTests(String database) {
    return new Object[] { new UpgradeAndCompare(database) };
}

It creates a new instance of the UpgradeAndCompare class with the desired database as a parameter. The class contains several test methods.

I have a testng.xml which contains reference to 3 other testng.xml-s. Each of the internally referenced xmls contain flag parameter (true|false).

In order to trigger the whole execution, I call testng.xml which in eventually calls all of the other internal xmls.

I want to be able to modify the annotations of the test methods in the UpgradeAndCompare class for each of its instance based on the parameter flags inside the internal xmls: Example: UpgradeAndCompare contains a method called test1

oracle.xml contains parameter runtest1 = false mssql.xml contains parameter runtest1 = true

test1 is run when the factory is called through mssql.xml, and is not run when it is called through oracle.xml

Is it possible?

Currently, IAnnotationTransformer is invoked only once, before everything else. Is this intended and if it is - why?

wenijinew commented 7 years ago

How can a test.xml contain other 3 test.xml-s?

vitanivanov commented 7 years ago

In order to reference other suites:

    <suite-files>
        <suite-file path="suite1.xml"/>
        <suite-file path="suite2.xml"/>
        <suite-file path="suite3.xml"/>
    </suite-files>
juherr commented 7 years ago

In fact, it currently works as designed: <suite-files> could be renamed <imports> At the end, from the TestNG point of view, you have only 1 suite.

I keep the issue open because it is something we should improve.