ImethodInterceptor not respected when using testgroup only

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

ImethodInterceptor not respected when using testgroup only

DD
Hi, 

I have an IMethodInterceptor which re-arranges the test methods based on priority of the class and the methods. 

It works fine when I specify which testclasses it has to run. But when I only specify which test group it has to run, the new sequence is not respected. 

Anyone any idee what can be the cause of this ? 

public class PriorityInterceptor implements IMethodInterceptor {

    @Override
    public List<IMethodInstance> intercept(List<IMethodInstance> methods,
                                           ITestContext context) {
        Comparator<IMethodInstance> comparator = new Comparator<IMethodInstance>() {

            private int getPriority(IMethodInstance mi) {
                int result = 0;
                int methodPrio = 0;
                int classPrio = 0;
               //Method method = mi.getMethod().getMethod();
                Method method = mi.getMethod().getConstructorOrMethod().getMethod();
                System.out.println("Testsd" + mi + "en" + method);
                Priority methodPriority = method.getAnnotation(Priority.class);
                System.out.println("Testsd" + methodPriority);
                Class<?> cls = method.getDeclaringClass();
                Priority classPriority = cls.getAnnotation(Priority.class);


                if (methodPriority != null) {
                    methodPrio = methodPriority.value();
                    classPrio = classPriority.value();

                    result = Integer.valueOf(String.valueOf(classPrio) + String.valueOf(methodPrio));
                    System.out.println("IfResult" + result);

                } else {

                    if (classPriority != null) {
                        classPrio = classPriority.value();
                        result = Integer.valueOf(String.valueOf(classPrio) + "0");
                        System.out.println("ElseResult" + result);
                    }
                }
                return result;
            }

            public int compare(IMethodInstance m1, IMethodInstance m2) {
                return getPriority(m1) - getPriority(m2);
            }

        };
        System.out.println(methods);
        IMethodInstance[] array = methods.toArray(new IMethodInstance[methods.size()]);
        System.out.println("lijst1" + Arrays.asList(array));
        Arrays.sort(array, comparator);
        System.out.println("lijst2" + Arrays.asList(array));

        return Arrays.asList(array);
    }

--
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: ImethodInterceptor not respected when using testgroup only

Krishnan Mahadevan

Dwight,

 

You have only shared how your interceptor looks like.

Can you please also share the following?

 

  1. TestNG version that you are working with. [ Latest released version as of today is 6.14.3]
  2. How do your test class samples look like?
  3. How does your @Priority annotation definition look like.

 

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/

Reply-To: <[hidden email]>
Date: Tuesday, March 6, 2018 at 3:48 AM
To: testng-users <[hidden email]>
Subject: [testng-users] ImethodInterceptor not respected when using testgroup only

 

Hi, 

 

I have an IMethodInterceptor which re-arranges the test methods based on priority of the class and the methods. 

 

It works fine when I specify which testclasses it has to run. But when I only specify which test group it has to run, the new sequence is not respected. 

 

Anyone any idee what can be the cause of this ? 

 

public class PriorityInterceptor implements IMethodInterceptor {

 

    @Override

    public List<IMethodInstance> intercept(List<IMethodInstance> methods,

                                           ITestContext context) {

        Comparator<IMethodInstance> comparator = new Comparator<IMethodInstance>() {

 

            private int getPriority(IMethodInstance mi) {

                int result = 0;

                int methodPrio = 0;

                int classPrio = 0;

               //Method method = mi.getMethod().getMethod();

                Method method = mi.getMethod().getConstructorOrMethod().getMethod();

                System.out.println("Testsd" + mi + "en" + method);

                Priority methodPriority = method.getAnnotation(Priority.class);

                System.out.println("Testsd" + methodPriority);

                Class<?> cls = method.getDeclaringClass();

                Priority classPriority = cls.getAnnotation(Priority.class);

 

 

                if (methodPriority != null) {

                    methodPrio = methodPriority.value();

                    classPrio = classPriority.value();

 

                    result = Integer.valueOf(String.valueOf(classPrio) + String.valueOf(methodPrio));

                    System.out.println("IfResult" + result);

 

                } else {

 

                    if (classPriority != null) {

                        classPrio = classPriority.value();

                        result = Integer.valueOf(String.valueOf(classPrio) + "0");

                        System.out.println("ElseResult" + result);

                    }

                }

                return result;

            }

 

            public int compare(IMethodInstance m1, IMethodInstance m2) {

                return getPriority(m1) - getPriority(m2);

            }

 

        };

        System.out.println(methods);

        IMethodInstance[] array = methods.toArray(new IMethodInstance[methods.size()]);

        System.out.println("lijst1" + Arrays.asList(array));

        Arrays.sort(array, comparator);

        System.out.println("lijst2" + Arrays.asList(array));

 

        return Arrays.asList(array);

    }

--
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.
DD
Reply | Threaded
Open this post in threaded view
|

Re: ImethodInterceptor not respected when using testgroup only

DD
Hi, 

TestNG version = 6.14.2

TestClass = 
@Priority(1)
public class Login extends BaseScenario
{
      @BeforeMethod(alwaysRun = true)
    public void setup()
    {
        .....
    }

    @Priority(3)
    @Test(description = "....", groups = "Regression")
    public void testLogin()
    {
      ....
    }

@Priority Definition

@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Priority {
    int value() default 0;
}

--
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: ImethodInterceptor not respected when using testgroup only

Krishnan Mahadevan

Dwight,

 

How about you sharing a full-fledged test sample (with just some sysouts), that I can use to reproduce the problem?

 

I am hoping that the sample would contain the following:

  1. Test classes
  2. Annotation (u have already provided that)
  3. Interceptor (u have already provided that)
  4. Suite xml which you use to execute the tests.

 

 

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/

Reply-To: <[hidden email]>
Date: Tuesday, March 6, 2018 at 1:44 PM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] ImethodInterceptor not respected when using testgroup only

 

Hi, 

 

TestNG version = 6.14.2

 

TestClass = 

@Priority(1)

public class Login extends BaseScenario

{

      @BeforeMethod(alwaysRun = true)

    public void setup()

    {

        .....

    }

 

    @Priority(3)

    @Test(description = "....", groups = "Regression")

    public void testLogin()

    {

      ....

    }

 

@Priority Definition

 

@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)

@Target({ElementType.METHOD, ElementType.TYPE})

public @interface Priority {

    int value() default 0;

}

--
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.
DD
Reply | Threaded
Open this post in threaded view
|

Re: ImethodInterceptor not respected when using testgroup only

DD
I've send you a PM

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