IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

Deepti Gupta
Hello, 

Expected Behavior: The documentation says that IExecutionListener will run only once in a suite run.    

Actual Behavior: When I use IExecutionListener as an annotation, it runs multiple times in a medium suite run. While if I include the listener in medium suite's XML file, it only runs once which is the expected behavior. 

I would love to get some thoughts from the community here on why am I seeing this behavior when I use IExecutionListener as an annotation. Thoughts? 

Here is a sample class and XML files: 


InvokedMethodListener: 

public class InvokedMethodListener implements IInvokedMethodListener{

public void afterInvocation(IInvokedMethod method, ITestResult testResult) {

System.out.println("AfterInvocation()");

}


public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {

System.out.println("BeforeInvocation()");

}

}


ExecutionListener: 

public class ExecutionListener implements IExecutionListener{


public void onExecutionStart() {

System.out.println("Notify that Suite has started");

}


public void onExecutionFinish() {

System.out.println("Notify that Suite has ended");

}


}


Sample Test Class: (IExecutionListener as an annotation)

package suite1;


import static org.testng.Assert.assertEquals;


import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

@Listeners({listeners.ExecutionListener.class,listeners.InvokedMethodListener.class})

public class TestClass1 {

@Test

public void test1() {

assertEquals(true, true);

}

@Test

public void test2() {

assertEquals(true, true);

}

@Test

public void test3() {

assertEquals(true, true);

}

@Test

public void test4() {

assertEquals(true, true);

}


}

Suite File: 

<suite name="mediumSuite">

<test name="exampletest2">

<classes>

<class name="suite2.TestClass3" />

<class name="suite2.TestClass4" />

</classes>

</test>

<suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  


<suite name="smallSuite">

<test name="exampletest1">

<classes>

<class name="suite1.TestClass1" />

<class name="suite1.TestClass2" />

</classes>

</test>

</suite>  


Output: 

Notify that Suite has started

Notify that Suite has started


BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()


===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================


BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()


===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended

Notify that Suite has ended



ExecutionListener in XML File

<suite name="mediumSuite">

<listeners>

        <listener class-name="listeners.ExecutionListener" />

</listeners>

<test name="exampletest2">

<classes>

<class name="suite2.TestClass3" />

<class name="suite2.TestClass4" />

</classes>

</test>

<suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  


Output

Notify that Suite has started


BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()


===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================


[TestNG] Running:


BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()


===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

Krishnan Mahadevan

Deepti,

 

Can you please try using the latest released version of TestNG viz., 6.14.3.

If you are still seeing the same behavior, I would request you to please file this as an issue here: https://github.com/cbeust/testng/issues

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/
Reply-To: <[hidden email]>
Date: Monday, February 26, 2018 at 9:43 AM
To: testng-users <[hidden email]>
Subject: [testng-users] IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

 

Hello, 

 

Expected Behavior: The documentation says that IExecutionListener will run only once in a suite run.    

 

Actual Behavior: When I use IExecutionListener as an annotation, it runs multiple times in a medium suite run. While if I include the listener in medium suite's XML file, it only runs once which is the expected behavior. 

 

I would love to get some thoughts from the community here on why am I seeing this behavior when I use IExecutionListener as an annotation. Thoughts? 

 

Here is a sample class and XML files: 

 

 

InvokedMethodListener: 

public class InvokedMethodListener implements IInvokedMethodListener{

      

       public void afterInvocation(IInvokedMethod method, ITestResult testResult) {

              System.out.println("AfterInvocation()");

       }

 

       public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {

              System.out.println("BeforeInvocation()");

             

       }

}

 

ExecutionListener: 

public class ExecutionListener implements IExecutionListener{

 

       public void onExecutionStart() {

              System.out.println("Notify that Suite has started");

             

       }

 

       public void onExecutionFinish() {

              System.out.println("Notify that Suite has ended");

             

       }

 

}

 

Sample Test Class: (IExecutionListener as an annotation)

package suite1;

 

import static org.testng.Assert.assertEquals;

 

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

@Listeners({listeners.ExecutionListener.class,listeners.InvokedMethodListener.class})

public class TestClass1 {

      

       @Test

       public void test1() {

              assertEquals(true, true);

       }

      

       @Test

       public void test2() {

              assertEquals(true, true);

       }

      

       @Test

       public void test3() {

              assertEquals(true, true);

       }

      

       @Test

       public void test4() {

              assertEquals(true, true);

       }

 

}

Suite File: 

<suite name="mediumSuite">

       <test name="exampletest2">

              <classes>

                     <class name="suite2.TestClass3" />

                     <class name="suite2.TestClass4" />

              </classes>

       </test>

       <suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  

 

<suite name="smallSuite">

       <test name="exampletest1">

              <classes>

                     <class name="suite1.TestClass1" />

                     <class name="suite1.TestClass2" />

              </classes>

       </test>

</suite>  

 

Output: 

Notify that Suite has started

Notify that Suite has started

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended

Notify that Suite has ended

 

 

ExecutionListener in XML File

<suite name="mediumSuite">

<listeners>

        <listener class-name="listeners.ExecutionListener" />

</listeners>

       <test name="exampletest2">

              <classes>

                     <class name="suite2.TestClass3" />

                     <class name="suite2.TestClass4" />

              </classes>

       </test>

       <suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  

 

Output

Notify that Suite has started

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================

 

[TestNG] Running:

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[hidden email].
To post to this group, send email to
[hidden email].
Visit this group at
https://groups.google.com/group/testng-users.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

Deepti Gupta
Thanks for your reply Krishnan. 

I have submitted an issue and here is the link: https://github.com/cbeust/testng/issues/1735. 

- Deepti 

On Monday, February 26, 2018 at 6:58:50 PM UTC-8, Krishnan Mahadevan wrote:

Deepti,

 

Can you please try using the latest released version of TestNG viz., 6.14.3.

If you are still seeing the same behavior, I would request you to please file this as an issue here: <a href="https://github.com/cbeust/testng/issues" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEkZFwrR886j6_KMGsK-VN4fP6q5g&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEkZFwrR886j6_KMGsK-VN4fP6q5g&#39;;return true;">https://github.com/cbeust/testng/issues

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/
Reply-To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="jMVZ2OdlCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Date: Monday, February 26, 2018 at 9:43 AM
To: testng-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="jMVZ2OdlCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Subject: [testng-users] IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

 

Hello, 

 

Expected Behavior: The documentation says that IExecutionListener will run only once in a suite run.    

 

Actual Behavior: When I use IExecutionListener as an annotation, it runs multiple times in a medium suite run. While if I include the listener in medium suite's XML file, it only runs once which is the expected behavior. 

 

I would love to get some thoughts from the community here on why am I seeing this behavior when I use IExecutionListener as an annotation. Thoughts? 

 

Here is a sample class and XML files: 

 

 

InvokedMethodListener: 

public class InvokedMethodListener implements IInvokedMethodListener{

      

       public void afterInvocation(IInvokedMethod method, ITestResult testResult) {

              System.out.println("AfterInvocation()");

       }

 

       public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {

              System.out.println("BeforeInvocation()");

             

       }

}

 

ExecutionListener: 

public class ExecutionListener implements IExecutionListener{

 

       public void onExecutionStart() {

              System.out.println("Notify that Suite has started");

             

       }

 

       public void onExecutionFinish() {

              System.out.println("Notify that Suite has ended");

             

       }

 

}

 

Sample Test Class: (IExecutionListener as an annotation)

package suite1;

 

import static org.testng.Assert.assertEquals;

 

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

@Listeners({listeners.ExecutionListener.class,listeners.InvokedMethodListener.class})

public class TestClass1 {

      

       @Test

       public void test1() {

              assertEquals(true, true);

       }

      

       @Test

       public void test2() {

              assertEquals(true, true);

       }

      

       @Test

       public void test3() {

              assertEquals(true, true);

       }

      

       @Test

       public void test4() {

              assertEquals(true, true);

       }

 

}

Suite File: 

<suite name="mediumSuite">

       <test name="exampletest2">

              <classes>

                     <class name="suite2.TestClass3" />

                     <class name="suite2.TestClass4" />

              </classes>

       </test>

       <suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  

 

<suite name="smallSuite">

       <test name="exampletest1">

              <classes>

                     <class name="suite1.TestClass1" />

                     <class name="suite1.TestClass2" />

              </classes>

       </test>

</suite>  

 

Output: 

Notify that Suite has started

Notify that Suite has started

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended

Notify that Suite has ended

 

 

ExecutionListener in XML File

<suite name="mediumSuite">

<listeners>

        <listener class-name="listeners.ExecutionListener" />

</listeners>

       <test name="exampletest2">

              <classes>

                     <class name="suite2.TestClass3" />

                     <class name="suite2.TestClass4" />

              </classes>

       </test>

       <suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  

 

Output

Notify that Suite has started

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================

 

[TestNG] Running:

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="jMVZ2OdlCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="jMVZ2OdlCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users@....
Visit this group at
<a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit
<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

Krishnan Mahadevan

Deepti,

 

I have raised a pull request to fix this bug : https://github.com/cbeust/testng/pull/1736

 

Once that is merged, your issue should be resolved.

 

You would need to start consuming TestNG 7.0.0-SNAPSHOT.

And oh btw, don’t forget to upgrade to JDK8 if you aren’t already on it. TestNG 7.0.0-SNAPSHOT (and 7.0.0 once its released) would now need JDK8

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/
Reply-To: <[hidden email]>
Date: Wednesday, March 28, 2018 at 5:59 PM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

 

Thanks for your reply Krishnan. 

 

I have submitted an issue and here is the link: https://github.com/cbeust/testng/issues/1735. 

 

- Deepti 

 

On Monday, February 26, 2018 at 6:58:50 PM UTC-8, Krishnan Mahadevan wrote:

Deepti,

 

Can you please try using the latest released version of TestNG viz., 6.14.3.

If you are still seeing the same behavior, I would request you to please file this as an issue here: https://github.com/cbeust/testng/issues

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/
Reply-To: <
<a href="javascript:" target="_blank">testng...@...>
Date: Monday, February 26, 2018 at 9:43 AM
To: testng-users <
<a href="javascript:" target="_blank">testng...@...>
Subject: [testng-users] IExecutionListener runs multiple times in a medium suite run when used as annotation but only once when added in XML file

 

Hello, 

 

Expected Behavior: The documentation says that IExecutionListener will run only once in a suite run.    

 

Actual Behavior: When I use IExecutionListener as an annotation, it runs multiple times in a medium suite run. While if I include the listener in medium suite's XML file, it only runs once which is the expected behavior. 

 

I would love to get some thoughts from the community here on why am I seeing this behavior when I use IExecutionListener as an annotation. Thoughts? 

 

Here is a sample class and XML files: 

 

 

InvokedMethodListener: 

public class InvokedMethodListener implements IInvokedMethodListener{

      

       public void afterInvocation(IInvokedMethod method, ITestResult testResult) {

              System.out.println("AfterInvocation()");

       }

 

       public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {

              System.out.println("BeforeInvocation()");

             

       }

}

 

ExecutionListener: 

public class ExecutionListener implements IExecutionListener{

 

       public void onExecutionStart() {

              System.out.println("Notify that Suite has started");

             

       }

 

       public void onExecutionFinish() {

              System.out.println("Notify that Suite has ended");

             

       }

 

}

 

Sample Test Class: (IExecutionListener as an annotation)

package suite1;

 

import static org.testng.Assert.assertEquals;

 

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

@Listeners({listeners.ExecutionListener.class,listeners.InvokedMethodListener.class})

public class TestClass1 {

      

       @Test

       public void test1() {

              assertEquals(true, true);

       }

      

       @Test

       public void test2() {

              assertEquals(true, true);

       }

      

       @Test

       public void test3() {

              assertEquals(true, true);

       }

      

       @Test

       public void test4() {

              assertEquals(true, true);

       }

 

}

Suite File: 

<suite name="mediumSuite">

       <test name="exampletest2">

              <classes>

                     <class name="suite2.TestClass3" />

                     <class name="suite2.TestClass4" />

              </classes>

       </test>

       <suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  

 

<suite name="smallSuite">

       <test name="exampletest1">

              <classes>

                     <class name="suite1.TestClass1" />

                     <class name="suite1.TestClass2" />

              </classes>

       </test>

</suite>  

 

Output: 

Notify that Suite has started

Notify that Suite has started

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended

Notify that Suite has ended

 

 

ExecutionListener in XML File

<suite name="mediumSuite">

<listeners>

        <listener class-name="listeners.ExecutionListener" />

</listeners>

       <test name="exampletest2">

              <classes>

                     <class name="suite2.TestClass3" />

                     <class name="suite2.TestClass4" />

              </classes>

       </test>

       <suite-files><suite-file path="src/test/resources/smallSuite.xml" /></suite-files>

</suite>  

 

Output

Notify that Suite has started

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

smallSuite

Total tests run: 8, Failures: 0, Skips: 0

===============================================

 

[TestNG] Running:

 

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

BeforeInvocation()

AfterInvocation()

 

===============================================

mediumSuite

Total tests run: 16, Failures: 0, Skips: 0

===============================================

Notify that Suite has ended

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
<a href="javascript:" target="_blank">testng-users+unsubscribe@....
To post to this group, send email to
<a href="javascript:" target="_blank">testng-users@....
Visit this group at
https://groups.google.com/group/testng-users.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[hidden email].
To post to this group, send email to
[hidden email].
Visit this group at
https://groups.google.com/group/testng-users.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.