IInvokedMethodListener and dependency-injection for "@BeforeMethod"-methods

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

IInvokedMethodListener and dependency-injection for "@BeforeMethod"-methods

KaiBra
This post has NOT been accepted by the mailing list yet.
Hello!

I've got a problem with the following situation:

In my BaseClass I defined the following method:
@BeforeMethod(alwaysRun = true)
        public void init() throws Exception {

}

This method is called before every tests (@Test), which e.g. look like this:
@Test(groups = { GROUP_A})
public void test1() throws Exception {

}
@Test(groups = { GROUP_B})
public void test2() throws Exception {

}

Now, what I would like to do is to implement a IInvokedMethodListener to stop some tests, which belong to a certain group, from being executed.
Of course I could just throw SKIP-Exceptions for the @Tests methods, but I would like to already skip the "init" Method for these tests.

I read that there ich something like "java.lang.reflect.Method" which I can add as a parameter to the init() method.
But how can I read this parameter in the implemented "IInvokedMethodListener" and scan the groups for the method which would be executed afterwards?

ublic class MethodInvocationListener implements IInvokedMethodListener {

        @Override
        public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
       

}
...


Thanks in advance for your help.

Regards,

Kai