A default IRetryAnalyzer for all tests in a test suite

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

A default IRetryAnalyzer for all tests in a test suite

rahul.thakur.xdev

Greetings,

I have a scenario where I am running hundreds of tests using TestNG
and would make sense if I were able to specify an IRetryAnalyzer impl
at the class level (rather than at method level), which could serve as
a default for all the tests contained in that test suite, and at the
same time could be conveniently overridden as well.

Currently, I am finding that we need to specify the 'retryAnalyzer'
attribute for each @Test. I had a look at the TestNG sources and it
appears that extending the Invoker might be a option. However, I
believe this might be a nice little feature to add to the TestNG
library itself.

WDYT?

Cheers,

Rahul

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: A default IRetryAnalyzer for all tests in a test suite

François Reynaud
Hi,

I had a similar problem, but for me, the retry are more linked to the test phase than the class itslef.
I got around without extending the invoker, using IAnnotationTransformer instead.

something like
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
        IRetryAnalyzer retry = annotation.getRetryAnalyzer();
        if (retry==null){
            annotation.setRetryAnalyzer(RetryAnalyser.class);
        }

    }

and I change the annotation tranformer based on my test phase.

thanks
françois

On Wed, Oct 7, 2009 at 2:47 PM, Rahul <[hidden email]> wrote:

Greetings,

I have a scenario where I am running hundreds of tests using TestNG
and would make sense if I were able to specify an IRetryAnalyzer impl
at the class level (rather than at method level), which could serve as
a default for all the tests contained in that test suite, and at the
same time could be conveniently overridden as well.

Currently, I am finding that we need to specify the 'retryAnalyzer'
attribute for each @Test. I had a look at the TestNG sources and it
appears that extending the Invoker might be a option. However, I
believe this might be a nice little feature to add to the TestNG
library itself.

WDYT?

Cheers,

Rahul




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: A default IRetryAnalyzer for all tests in a test suite

Cédric Beust ♔
In reply to this post by rahul.thakur.xdev
Hi Rahul,

Declare your @Test(retryAnalyzer=...) annotation at the class level and it will apply to all your public methods (you can still add individual @Test annotations on your methods with additional attributes).

--
Cedric


On Wed, Oct 7, 2009 at 6:47 AM, Rahul <[hidden email]> wrote:

Greetings,

I have a scenario where I am running hundreds of tests using TestNG
and would make sense if I were able to specify an IRetryAnalyzer impl
at the class level (rather than at method level), which could serve as
a default for all the tests contained in that test suite, and at the
same time could be conveniently overridden as well.

Currently, I am finding that we need to specify the 'retryAnalyzer'
attribute for each @Test. I had a look at the TestNG sources and it
appears that extending the Invoker might be a option. However, I
believe this might be a nice little feature to add to the TestNG
library itself.

WDYT?

Cheers,

Rahul





--
Cédric



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: A default IRetryAnalyzer for all tests in a test suite

rahul.thakur.xdev

Hi Cedric,

I tried this at the Class level but no joy :-(

I am using TestNG 5.9. I will try and debug shortly and see what's
happening.

Cheers,

Rahul



On Oct 7, 8:05 pm, Cédric Beust ♔ <[hidden email]> wrote:

> Hi Rahul,
>
> Declare your @Test(retryAnalyzer=...) annotation at the class level and it
> will apply to all your public methods (you can still add individual @Test
> annotations on your methods with additional attributes).
>
> --
> Cedric
>
>
>
>
>
> On Wed, Oct 7, 2009 at 6:47 AM, Rahul <[hidden email]> wrote:
>
> > Greetings,
>
> > I have a scenario where I am running hundreds of tests using TestNG
> > and would make sense if I were able to specify an IRetryAnalyzer impl
> > at the class level (rather than at method level), which could serve as
> > a default for all the tests contained in that test suite, and at the
> > same time could be conveniently overridden as well.
>
> > Currently, I am finding that we need to specify the 'retryAnalyzer'
> > attribute for each @Test. I had a look at the TestNG sources and it
> > appears that extending the Invoker might be a option. However, I
> > believe this might be a nice little feature to add to the TestNG
> > library itself.
>
> > WDYT?
>
> > Cheers,
>
> > Rahul
>
> --
> ***Cédric
> *
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: A default IRetryAnalyzer for all tests in a test suite

rahul.thakur.xdev
In reply to this post by François Reynaud

Hello again,

Just a quick update:
François' suggestion about using an IAnnotationTransformer impl works,
so I have taken that alternative.

Thanks François!

Cheers,

Rahul



On Oct 7, 8:02 pm, François Reynaud <[hidden email]>
wrote:

> Hi,
>
> I had a similar problem, but for me, the retry are more linked to the test
> phase than the class itslef.
> I got around without extending the invoker, using IAnnotationTransformer
> instead.
>
> something like
> public void transform(ITestAnnotation annotation, Class testClass,
> Constructor testConstructor, Method testMethod) {
>         IRetryAnalyzer retry = annotation.getRetryAnalyzer();
>         if (retry==null){
>             annotation.setRetryAnalyzer(RetryAnalyser.class);
>         }
>
>     }
>
> and I change the annotation tranformer based on my test phase.
>
> thanks
> françois
>
>
>
> On Wed, Oct 7, 2009 at 2:47 PM, Rahul <[hidden email]> wrote:
>
> > Greetings,
>
> > I have a scenario where I am running hundreds of tests using TestNG
> > and would make sense if I were able to specify an IRetryAnalyzer impl
> > at the class level (rather than at method level), which could serve as
> > a default for all the tests contained in that test suite, and at the
> > same time could be conveniently overridden as well.
>
> > Currently, I am finding that we need to specify the 'retryAnalyzer'
> > attribute for each @Test. I had a look at the TestNG sources and it
> > appears that extending the Invoker might be a option. However, I
> > believe this might be a nice little feature to add to the TestNG
> > library itself.
>
> > WDYT?
>
> > Cheers,
>
> > Rahul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: A default IRetryAnalyzer for all tests in a test suite

Venkatesh Aarelly
Hi,

try below steps, its worked for me.

import org.testng.IRetryAnalyzer;

import org.testng.ITestResult;


public class RetryAnalyzer implements IRetryAnalyzer {

    private int retryCount = 0;

    private int maxRetryCount = 1;


// Below method returns 'true' if the test method has to be retried else 'false' 

//and it takes the 'Result' as parameter of the test method that just ran

    public boolean retry(ITestResult result) {

        if (retryCount < maxRetryCount) {

            System.out.println("Retrying test " + result.getName() + " with status "

                    + getResultStatusName(result.getStatus()) + " for the " + (retryCount+1) + " time(s).");

            retryCount++;

            return true;

        }

        return false;

    }

    

    public String getResultStatusName(int status) {

    String resultName = null;

    if(status==1)

    resultName = "SUCCESS";

    if(status==2)

    resultName = "FAILURE";

    if(status==3)

    resultName = "SKIP";

return resultName;

    }

}



import java.lang.reflect.Constructor;

import java.lang.reflect.Method;


import org.testng.IAnnotationTransformer;

import org.testng.IRetryAnalyzer;

import org.testng.annotations.ITestAnnotation;


public class RetryListener implements IAnnotationTransformer {

    @Override

    public void transform(ITestAnnotation annotation, Class testClass,

            Constructor testConstructor, Method testMethod) {

        IRetryAnalyzer retry = annotation.getRetryAnalyzer();

        if (retry == null) {

            annotation.setRetryAnalyzer(RetryAnalyzer.class);

        }

    }

}



import org.testng.Assert;

import org.testng.ITestContext;

import org.testng.ITestNGMethod;

import org.testng.annotations.AfterSuite;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;


@Listeners(RetryListener.class)

public class SampleExample {


@BeforeSuite(alwaysRun = true)

public void beforeSuite(ITestContext context) {

    for (ITestNGMethod method : context.getAllTestMethods()) {

        method.setRetryAnalyzer(new RetryAnalyzer());

    }

}

@Test

public void test1(){

Assert.assertTrue(true);

}

@Test

public void test2(){

Assert.assertTrue(true);

}

@AfterSuite(alwaysRun = true)

public void afterSuite(ITestContext context) {

}

}


it will run test class level..




On Thursday, October 8, 2009 at 7:04:02 PM UTC+5:30, Rahul wrote:
Hello again,

Just a quick update:
François' suggestion about using an IAnnotationTransformer impl works,
so I have taken that alternative.

Thanks François!

Cheers,

Rahul



On Oct 7, 8:02 pm, François Reynaud <[hidden email]>
wrote:

> Hi,
>
> I had a similar problem, but for me, the retry are more linked to the test
> phase than the class itslef.
> I got around without extending the invoker, using IAnnotationTransformer
> instead.
>
> something like
> public void transform(ITestAnnotation annotation, Class testClass,
> Constructor testConstructor, Method testMethod) {
>         IRetryAnalyzer retry = annotation.getRetryAnalyzer();
>         if (retry==null){
>             annotation.setRetryAnalyzer(RetryAnalyser.class);
>         }
>
>     }
>
> and I change the annotation tranformer based on my test phase.
>
> thanks
> françois
>
>
>
> On Wed, Oct 7, 2009 at 2:47 PM, Rahul <[hidden email]> wrote:
>
> > Greetings,
>
> > I have a scenario where I am running hundreds of tests using TestNG
> > and would make sense if I were able to specify an IRetryAnalyzer impl
> > at the class level (rather than at method level), which could serve as
> > a default for all the tests contained in that test suite, and at the
> > same time could be conveniently overridden as well.
>
> > Currently, I am finding that we need to specify the 'retryAnalyzer'
> > attribute for each @Test. I had a look at the TestNG sources and it
> > appears that extending the Invoker might be a option. However, I
> > believe this might be a nice little feature to add to the TestNG
> > library itself.
>
> > WDYT?
>
> > Cheers,
>
> > Rahul
The information in this message may be proprietary and/or confidential, and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify ATMECS and delete it from your computer.

--
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: A default IRetryAnalyzer for all tests in a test suite

Giri Tharan
Hi Venkatesh,

I tried the same approach which you have mentioned below but @listerner is not getting invoked, when I checked at the testng documentation i see this 
"The @Listeners annotation can contain any class that extends org.testng.ITestNGListener except IAnnotationTransformer and IAnnotationTransformer2. The reason is that these listeners need to be known very early in the process so that TestNG can use them to rewrite your annotations, therefore you need to specify these listeners in your testng.xml file."

Can you help if I am missing something

On Tuesday, August 2, 2016 at 7:29:01 AM UTC-5, Venkatesh Aarelly wrote:
Hi,

try below steps, its worked for me.

import org.testng.IRetryAnalyzer;

import org.testng.ITestResult;


public class RetryAnalyzer implements IRetryAnalyzer {

    private int retryCount = 0;

    private int maxRetryCount = 1;


// Below method returns 'true' if the test method has to be retried else 'false' 

//and it takes the 'Result' as parameter of the test method that just ran

    public boolean retry(ITestResult result) {

        if (retryCount < maxRetryCount) {

            System.out.println("Retrying test " + result.getName() + " with status "

                    + getResultStatusName(result.getStatus()) + " for the " + (retryCount+1) + " time(s).");

            retryCount++;

            return true;

        }

        return false;

    }

    

    public String getResultStatusName(int status) {

    String resultName = null;

    if(status==1)

    resultName = "SUCCESS";

    if(status==2)

    resultName = "FAILURE";

    if(status==3)

    resultName = "SKIP";

return resultName;

    }

}



import java.lang.reflect.Constructor;

import java.lang.reflect.Method;


import org.testng.IAnnotationTransformer;

import org.testng.IRetryAnalyzer;

import org.testng.annotations.ITestAnnotation;


public class RetryListener implements IAnnotationTransformer {

    @Override

    public void transform(ITestAnnotation annotation, Class testClass,

            Constructor testConstructor, Method testMethod) {

        IRetryAnalyzer retry = annotation.getRetryAnalyzer();

        if (retry == null) {

            annotation.setRetryAnalyzer(RetryAnalyzer.class);

        }

    }

}



import org.testng.Assert;

import org.testng.ITestContext;

import org.testng.ITestNGMethod;

import org.testng.annotations.AfterSuite;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;


@Listeners(RetryListener.class)

public class SampleExample {


@BeforeSuite(alwaysRun = true)

public void beforeSuite(ITestContext context) {

    for (ITestNGMethod method : context.getAllTestMethods()) {

        method.setRetryAnalyzer(new RetryAnalyzer());

    }

}

@Test

public void test1(){

Assert.assertTrue(true);

}

@Test

public void test2(){

Assert.assertTrue(true);

}

@AfterSuite(alwaysRun = true)

public void afterSuite(ITestContext context) {

}

}


it will run test class level..




On Thursday, October 8, 2009 at 7:04:02 PM UTC+5:30, Rahul wrote:
Hello again,

Just a quick update:
François' suggestion about using an IAnnotationTransformer impl works,
so I have taken that alternative.

Thanks François!

Cheers,

Rahul



On Oct 7, 8:02 pm, François Reynaud <[hidden email]>
wrote:

> Hi,
>
> I had a similar problem, but for me, the retry are more linked to the test
> phase than the class itslef.
> I got around without extending the invoker, using IAnnotationTransformer
> instead.
>
> something like
> public void transform(ITestAnnotation annotation, Class testClass,
> Constructor testConstructor, Method testMethod) {
>         IRetryAnalyzer retry = annotation.getRetryAnalyzer();
>         if (retry==null){
>             annotation.setRetryAnalyzer(RetryAnalyser.class);
>         }
>
>     }
>
> and I change the annotation tranformer based on my test phase.
>
> thanks
> françois
>
>
>
> On Wed, Oct 7, 2009 at 2:47 PM, Rahul <[hidden email]> wrote:
>
> > Greetings,
>
> > I have a scenario where I am running hundreds of tests using TestNG
> > and would make sense if I were able to specify an IRetryAnalyzer impl
> > at the class level (rather than at method level), which could serve as
> > a default for all the tests contained in that test suite, and at the
> > same time could be conveniently overridden as well.
>
> > Currently, I am finding that we need to specify the 'retryAnalyzer'
> > attribute for each @Test. I had a look at the TestNG sources and it
> > appears that extending the Invoker might be a option. However, I
> > believe this might be a nice little feature to add to the TestNG
> > library itself.
>
> > WDYT?
>
> > Cheers,
>
> > Rahul
The information in this message may be proprietary and/or confidential, and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify ATMECS and delete it from your computer.

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