-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[FR] Controlling the inclusion of the listener at runtime #2381
Comments
@shaburov - I am not sure I quite understood the issue.
TestNG listener is essentially any TestNG interface that extends
I realise that you are asking for a new feature. So before we tread down that path can you please explain what exactly are you trying to do here ? |
@krmahadevan Hello! |
@shaburov - Wouldn't a
I still didnt understand this statement. AFAIK all the interfaces under |
I need the @listeners(IntellijIdeaTestNgPluginListener.class) to work only in the IDE and be disabled when launched from the console. How I can do that? Do you have any idea? |
You can do something like this:
That should take care of your requirement. @juherr - WDYT ? |
Like Another way for optional listeners could be something like: @OptionalListeners(IntellijIdeaTestNgPluginListener.class)
@Listeners(OptionalListener.class)
public abstract class BaseTest { } where OptionalListener will be responsible for instantiating and using listeners from |
My friends. |
@shaburov - Would you be willing to submit a PR that shows us what you are proposing ? The method interceptor or the annotation transformer exists for this very reason. |
Here's how this can be done. Version: Sample import org.testng.IAnnotationTransformer;
import org.testng.annotations.IListenersAnnotation;
import java.util.Arrays;
public class SampleAnnotationTransformer implements IAnnotationTransformer {
private static final String intellijClassName = "com.intellij.rt.testng.IDEARemoteTestNG";
@SuppressWarnings("unchecked")
@Override
public void transform(IListenersAnnotation annotation, Class<?> testClass) {
if (isRunningInIntelliJ()) {
annotation.setValue(new Class[]{});
}
}
private static boolean isRunningInIntelliJ() {
return Arrays.stream(Thread.currentThread().getStackTrace())
.map(StackTraceElement::getClassName)
.anyMatch(intellijClassName::equalsIgnoreCase);
}
} The above annotation transformer checks if the current execution is from within IntelliJ by inspecting the current thread's stack trace and looking for the IntelliJ specific class in it. Once it finds it, it disables the listener values found in the This annotation transformer needs to be wired in via the service loading approach that TestNG supports. This should now help us with dynamically enabling/disabling listeners that are being wired in ONLY via the
|
An annotation Listeners is added to the class
Expected behavior
ITestNGListener extended/implemented IParameterizable should allow disabling the listener at runtime
The text was updated successfully, but these errors were encountered: