How to give test listeners path when listeners.java is in a separate package

96 views
Skip to first unread message

MCD dotCom

unread,
Feb 22, 2022, 4:26:46 PM2/22/22
to testng-users
Hello,

TestListener and BaseTest are residing in different directories within the project. 

TestListener.java directory:
\src\test\java\Utilities

BaseTest.java directory:
\src\main\java\xxx\xxxx\base

I like to include test listeners in my BaseTest. All the testNG tests are extending the BaseTest.

In BaseTest.java, 

@Listeners( \src\test\java\Utilities.ListenerTest.class) // I am getting syntax error here

public class BaseTest {        
.....
}

However, if I keep the BaseTest and TestListener under the same package, it works as following:

@Listeners( Utilities.ListenerTest.class) // package.class name

But in my case, I like to keep these files in separate directories as mention above. 

How do I include the Listener class in BaseTest when BaseTest and ListenerTest are in two different directories?

Thank you!

Baubak

unread,
Feb 24, 2022, 9:28:26 AM2/24/22
to testng-users
Hi,

This is not really a testng issue. Although objects in src/test/java can access src/main/java, the opposite is not true. I suggest that you move your listener to the same location as you BaseTest. (your can replace their locations also, but I don't think it is a good idea).

Another solution is to declare your listener in the testng.xml file instead of inline in the class BaseTest. This way it can be anywhere.

Good luck,

Baubak
Reply all
Reply to author
Forward
0 new messages