Alternative for IMethodInterceptor

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

Alternative for IMethodInterceptor

santhosh soma
Hi All,

I am looking for the alternative for the listener "IMethodInterceptor".

Basically I am looking for the way to get the list of the test methods included for the run with out running the testng.xml. 

I have some requirement to get the list of scoped test method with some programmatic way not with the listner for which we need to run tests.

Note: We are using beanshell to include the test methods with the group name.

Below is the sample example:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite thread-count=“1” configfailurepolicy="continue" name=“SAMPLETEST SUITE” parallel="tests">

  <test name=“SAMPLE” group-by-instances="true">

    <method-selectors>

      <method-selector>

        <script language="beanshell">

          <![CDATA[(groups.containsKey("P0")) && (groups.containsKey(“P1”))]]>

        </script>

      </method-selector>

    </method-selectors>

    <packages>

      <package name="*">

        <include name=".*"/>

      </package> 

    </packages>

  </test> 

</suite> 


The above configuration is the input for me to parse and get the list of the methods. But I am not sure that how to get the list of the included methods from the bean shell with above xml in programatic way.


Thanks
Santhosh.

--
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: Alternative for IMethodInterceptor

⇜Krishnan Mahadevan⇝

Santhosh,

 

TestNG currently doesn’t have something called a “dry-run” mode wherein you could have easily figured out the list of methods that would be executed, but without actually those methods being executed.

 

The BeanShell that you shared is an example of method selection and not necessarily method interception. These two are two different things.

 

Beanshell is another way of plugging in a org.testng.IMethodSelector using which you get to decide which method to include and which one not to.

 

The org.testng.IMethodInterceptor basically lets you do the following :

 

  • Re-order the tests (For e.g., you might want to sort the tests based on some annotation, such that the fast running tests run first and then the slow ones)
  • Increase/decrease the number of tests that would be executed by TestNG. Take a look at this blog post that Cedric wrote, wherein he shows how to leverage the IMethodInterceptor and simulate Mock testing

 

So for your usecase the IMethodInterceptor should suffice I guess, wherein you get the list of methods that would be executed. But since TestNG doesn’t have a dry-run option yet [ There’s a bug that is tracking this https://github.com/cbeust/testng/issues/1503 ], you could perhaps go extreme and just invoke System.exit(0) from within your Interceptor after you have gotten the list of methods, and maybe print it or something. Just talking loud here!

 

 

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/

 

From: <[hidden email]> on behalf of santhosh <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, November 29, 2017 at 11:13 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Alternative for IMethodInterceptor

 

Hi All,

 

I am looking for the alternative for the listener "IMethodInterceptor".

 

Basically I am looking for the way to get the list of the test methods included for the run with out running the testng.xml. 

 

I have some requirement to get the list of scoped test method with some programmatic way not with the listner for which we need to run tests.

 

Note: We are using beanshell to include the test methods with the group name.

 

Below is the sample example:

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite thread-count=“1” configfailurepolicy="continue" name=“SAMPLETEST SUITE” parallel="tests">

  <test name=“SAMPLE” group-by-instances="true">

    <method-selectors>

      <method-selector>

        <script language="beanshell">

          <![CDATA[(groups.containsKey("P0")) && (groups.containsKey(“P1”))]]>

        </script>

      </method-selector>

    </method-selectors>

    <packages>

      <package name="*">

        <include name=".*"/>

      </package> 

    </packages>

  </test> 

</suite> 

 

The above configuration is the input for me to parse and get the list of the methods. But I am not sure that how to get the list of the included methods from the bean shell with above xml in programatic way.

 

Thanks

Santhosh.

--
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: Alternative for IMethodInterceptor

Cédric Beust ♔-2

Krishnan,

FYI, it would be pretty easy to implement -dryRun:

  • Create a subclass of IWorker which, instead of actually running a test, immediately returns with a success status
  • Return these workers from the IWorkerFactory.

-- 
Cédric


On Wed, Nov 29, 2017 at 6:56 PM, Krishnan Mahadevan <[hidden email]> wrote:

Santhosh,

 

TestNG currently doesn’t have something called a “dry-run” mode wherein you could have easily figured out the list of methods that would be executed, but without actually those methods being executed.

 

The BeanShell that you shared is an example of method selection and not necessarily method interception. These two are two different things.

 

Beanshell is another way of plugging in a org.testng.IMethodSelector using which you get to decide which method to include and which one not to.

 

The org.testng.IMethodInterceptor basically lets you do the following :

 

  • Re-order the tests (For e.g., you might want to sort the tests based on some annotation, such that the fast running tests run first and then the slow ones)
  • Increase/decrease the number of tests that would be executed by TestNG. Take a look at this blog post that Cedric wrote, wherein he shows how to leverage the IMethodInterceptor and simulate Mock testing

 

So for your usecase the IMethodInterceptor should suffice I guess, wherein you get the list of methods that would be executed. But since TestNG doesn’t have a dry-run option yet [ There’s a bug that is tracking this https://github.com/cbeust/testng/issues/1503 ], you could perhaps go extreme and just invoke System.exit(0) from within your Interceptor after you have gotten the list of methods, and maybe print it or something. Just talking loud here!

 

 

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/

 

From: <[hidden email]> on behalf of santhosh <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, November 29, 2017 at 11:13 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Alternative for IMethodInterceptor

 

Hi All,

 

I am looking for the alternative for the listener "IMethodInterceptor".

 

Basically I am looking for the way to get the list of the test methods included for the run with out running the testng.xml. 

 

I have some requirement to get the list of scoped test method with some programmatic way not with the listner for which we need to run tests.

 

Note: We are using beanshell to include the test methods with the group name.

 

Below is the sample example:

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite thread-count=“1” configfailurepolicy="continue" name=“SAMPLETEST SUITE” parallel="tests">

  <test name=“SAMPLE” group-by-instances="true">

    <method-selectors>

      <method-selector>

        <script language="beanshell">

          <![CDATA[(groups.containsKey("P0")) && (groups.containsKey(“P1”))]]>

        </script>

      </method-selector>

    </method-selectors>

    <packages>

      <package name="*">

        <include name=".*"/>

      </package> 

    </packages>

  </test> 

</suite> 

 

The above configuration is the input for me to parse and get the list of the methods. But I am not sure that how to get the list of the included methods from the bean shell with above xml in programatic way.

 

Thanks

Santhosh.

--
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.

--
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: Alternative for IMethodInterceptor

⇜Krishnan Mahadevan⇝

Thanks Cedric. I have self-assigned https://github.com/cbeust/testng/issues/1503

I will give this a try and raise a PR.

 

 

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/

 

From: <[hidden email]> on behalf of Cédric Beust <[hidden email]>
Reply-To: <[hidden email]>
Date: Thursday, November 30, 2017 at 9:45 AM
To: <[hidden email]>
Subject: Re: [testng-users] Alternative for IMethodInterceptor

 

Krishnan,

FYI, it would be pretty easy to implement -dryRun:

·         Create a subclass of IWorker which, instead of actually running a test, immediately returns with a success status

·         Return these workers from the IWorkerFactory.


-- 

Cédric

 

On Wed, Nov 29, 2017 at 6:56 PM, Krishnan Mahadevan <[hidden email]> wrote:

Santhosh,

 

TestNG currently doesn’t have something called a “dry-run” mode wherein you could have easily figured out the list of methods that would be executed, but without actually those methods being executed.

 

The BeanShell that you shared is an example of method selection and not necessarily method interception. These two are two different things.

 

Beanshell is another way of plugging in a org.testng.IMethodSelector using which you get to decide which method to include and which one not to.

 

The org.testng.IMethodInterceptor basically lets you do the following :

 

  • Re-order the tests (For e.g., you might want to sort the tests based on some annotation, such that the fast running tests run first and then the slow ones)
  • Increase/decrease the number of tests that would be executed by TestNG. Take a look at this blog post that Cedric wrote, wherein he shows how to leverage the IMethodInterceptor and simulate Mock testing

 

So for your usecase the IMethodInterceptor should suffice I guess, wherein you get the list of methods that would be executed. But since TestNG doesn’t have a dry-run option yet [ There’s a bug that is tracking this https://github.com/cbeust/testng/issues/1503 ], you could perhaps go extreme and just invoke System.exit(0) from within your Interceptor after you have gotten the list of methods, and maybe print it or something. Just talking loud here!

 

 

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/

 

From: <[hidden email]> on behalf of santhosh <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, November 29, 2017 at 11:13 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Alternative for IMethodInterceptor

 

Hi All,

 

I am looking for the alternative for the listener "IMethodInterceptor".

 

Basically I am looking for the way to get the list of the test methods included for the run with out running the testng.xml. 

 

I have some requirement to get the list of scoped test method with some programmatic way not with the listner for which we need to run tests.

 

Note: We are using beanshell to include the test methods with the group name.

 

Below is the sample example:

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite thread-count=“1” configfailurepolicy="continue" name=“SAMPLETEST SUITE” parallel="tests">

  <test name=“SAMPLE” group-by-instances="true">

    <method-selectors>

      <method-selector>

        <script language="beanshell">

          <![CDATA[(groups.containsKey("P0")) && (groups.containsKey(“P1”))]]>

        </script>

      </method-selector>

    </method-selectors>

    <packages>

      <package name="*">

        <include name=".*"/>

      </package> 

    </packages>

  </test> 

</suite> 

 

The above configuration is the input for me to parse and get the list of the methods. But I am not sure that how to get the list of the included methods from the bean shell with above xml in programatic way.

 

Thanks

Santhosh.

--
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.

 

--
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: Alternative for IMethodInterceptor

kool79
In reply to this post by santhosh soma
I use for this purpose interfaces IHookable, IConfigurable:

public abstract class BaseTest implements IHookable, IConfigurable {

@Override
public void run(IHookCallBack callBack, ITestResult testResult) {

if (Config.getProperty("skip_test_execution", false))
return;
callBack.runTestMethod(testResult);
}


@Override
public void run(IConfigureCallBack callBack, ITestResult testResult) {

if (Config.getProperty("skip_test_execution", false)) return;
callBack.runConfigurationMethod(testResult);
}
}
But all your tests should extend this class

среда, 29 ноября 2017 г., 19:43:16 UTC+2 пользователь santhosh написал:
Hi All,

I am looking for the alternative for the listener "IMethodInterceptor".

Basically I am looking for the way to get the list of the test methods included for the run with out running the testng.xml. 

I have some requirement to get the list of scoped test method with some programmatic way not with the listner for which we need to run tests.

Note: We are using beanshell to include the test methods with the group name.

Below is the sample example:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">

<suite thread-count=“1” configfailurepolicy="continue" name=“SAMPLETEST SUITE” parallel="tests">

  <test name=“SAMPLE” group-by-instances="true">

    <method-selectors>

      <method-selector>

        <script language="beanshell">

          <![CDATA[(groups.containsKey("P0")) && (groups.containsKey(“P1”))]]>

        </script>

      </method-selector>

    </method-selectors>

    <packages>

      <package name="*">

        <include name=".*"/>

      </package> 

    </packages>

  </test> 

</suite> 


The above configuration is the input for me to parse and get the list of the methods. But I am not sure that how to get the list of the included methods from the bean shell with above xml in programatic way.


Thanks
Santhosh.

--
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: Alternative for IMethodInterceptor

santhosh soma
Thanks for the quick response. 

On Sat, Dec 2, 2017 at 1:52 AM, <[hidden email]> wrote:
I use for this purpose interfaces IHookable, IConfigurable:

public abstract class BaseTest implements IHookable, IConfigurable {

@Override
public void run(IHookCallBack callBack, ITestResult testResult) {

if (Config.getProperty("skip_test_execution", false))
return;
callBack.runTestMethod(testResult);
}


@Override
public void run(IConfigureCallBack callBack, ITestResult testResult) {

if (Config.getProperty("skip_test_execution", false)) return;
callBack.runConfigurationMethod(testResult);
}
}
But all your tests should extend this class

среда, 29 ноября 2017 г., 19:43:16 UTC+2 пользователь santhosh написал:
Hi All,

I am looking for the alternative for the listener "IMethodInterceptor".

Basically I am looking for the way to get the list of the test methods included for the run with out running the testng.xml. 

I have some requirement to get the list of scoped test method with some programmatic way not with the listner for which we need to run tests.

Note: We are using beanshell to include the test methods with the group name.

Below is the sample example:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite thread-count=“1” configfailurepolicy="continue" name=“SAMPLETEST SUITE” parallel="tests">

  <test name=“SAMPLE” group-by-instances="true">

    <method-selectors>

      <method-selector>

        <script language="beanshell">

          <![CDATA[(groups.containsKey("P0")) && (groups.containsKey(“P1”))]]>

        </script>

      </method-selector>

    </method-selectors>

    <packages>

      <package name="*">

        <include name=".*"/>

      </package> 

    </packages>

  </test> 

</suite> 


The above configuration is the input for me to parse and get the list of the methods. But I am not sure that how to get the list of the included methods from the bean shell with above xml in programatic way.


Thanks
Santhosh.

--
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.