cbeust/testng — Issue #171: ISuiteListener.onStart method called mulitple times if i have multiple test elements in xml configuration file
Author: chanjarster
Created: 2012-02-18 07:03:39+00:00
State: open

Hi

I got a weird result if i declare a ```@Listeners```, which define my implementation of ```ISuiteListener```, on a __base class__ and define multiple test elements, each of which include only one test class inherited from that __base class__, in the xml configration file.

Here is my testng.xml file:

```xml

```

My implementation of ```ISuiteListener```

```java
public class SuiteListener implements ISuiteListener {

@Override
public void onFinish(ISuite suite) {
// TODO Auto-generated method stub
}

@Override
public void onStart(ISuite suite) {
System.out.println("*******Suite Listener Start");
System.out.println(":::::::suite detected: " + suite.getName());
for(XmlTest xmlTest : suite.getXmlSuite().getTests()) {
System.out.println(":::::::test detected: " + xmlTest.getName());
for(XmlClass xmlClass : xmlTest.getClasses()) {
System.out.println(":::::::class detected: " + xmlClass.getName());
}
}
System.out.println("*******Suite Listener End\n");
}
}
```

TestBase.java

```java
@Listeners(SuiteListener.class)
public class TestBase {
}
```

TestA.java

```java
public class TestA extends TestBase {
@Test
public void test() {
}
}
```

TestB.java

```java
public class TestB extends TestBase {
@Test
public void test() {
}
}
```

After I run the test, the console output is

```
*******Suite Listener Start
:::::::suite detected: suite
:::::::test detected: test1
:::::::class detected: org.beangle.webtest.temp.TestA
:::::::test detected: test2
:::::::class detected: org.beangle.webtest.temp.TestB
*******Suite Listener End

*******Suite Listener Start
:::::::suite detected: suite
:::::::test detected: test1
:::::::class detected: org.beangle.webtest.temp.TestA
:::::::test detected: test2
:::::::class detected: org.beangle.webtest.temp.TestB
*******Suite Listener End
```

I am confused about the result. ```SuiteListener.onStart``` method is called __twice__, is that the expected result ?

Can I make ```SuiteListener.onStart``` method called __only once__?

Thanks in advance.