Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the name of the class that is acted upon by listener of TestNG?
    primarykey
    data
    text
    <p>Hello I have a simple <em>testNG</em> project which has a <code>SampleTest.java</code> class file which has 2 test cases and I have added a listener called MyListener to it . For this I have a <code>MyListener.java</code> class file which extends the <em>TestListener of TestNG</em> where in I'm printing pass or fail or skipped depending upon the test case execution. So every time i run SampleTest I can see Pass/fail in the console.. But I want it with the classname </p> <p><strong>My problem statement is, How can i get the Test Case file name (i.e. Sampletest here) in the MyListener class???</strong> I tried with stacktrace but no help.. As I guess its not being called but its just acting upon/listening to the testcases in the file.. Please let me know how can I get the name of that class in listener????</p> <p><strong>SampleTest.java:</strong></p> <pre><code>package com.abc; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @Listeners({ com.mindtree.MyListener.class}) public class SampleTest { @Test public void SampleTest() throws Exception{ System.out.println("Hello world"); } @Test public void SampleTest1() throws Exception{ System.out.println("Hello Swarna"); } } </code></pre> <p><strong>MyListener.java:</strong></p> <pre><code>package com.abc; import org.testng.ITestResult; import org.testng.TestListenerAdapter; public class MyListener extends TestListenerAdapter { private int m_count = 0; @Override public void onTestFailure(ITestResult tr) { log("Fail"); } @Override public void onTestSkipped(ITestResult tr) { log("Skipped"); } @Override public void onTestSuccess(ITestResult tr) { log("\nSuccess\n"); ## WANT TO PRINT HERE THE TESTCASE CLASS NAME } private void log(String string) { System.out.print(string); if (++m_count % 40 == 0) { System.out.println(""); } } } </code></pre> <p>but wont work for multiple testcase files.. Just create an object of SampleTest in MyListener access the classname through getters and setters</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload