@BeforeMethod set alwaysRun=true

394 views
Skip to first unread message

Andre

unread,
May 9, 2008, 10:35:14 AM5/9/08
to testng-users
Hallo,

how can I set alwaysRun=true for all setUp methods witch use the
@BeforeMethod Annotation?

I have try it with an Transformer, but it dosn't work:

public class MyTransformer implements IAnnotationTransformer {

public void transform(ITest test, Class cls, Constructor
constructor,
Method method) {

test.setAlwaysRun(true);

}
}



pom.xml:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>
MyTransformer
</value>
</property>
</properties>
</configuration>
<version>2.4.2</version>
</plugin>

We use Maven2 with surfire-plugin to call testng

I hope anyone can help me.

Cédric Beust ♔

unread,
May 9, 2008, 10:59:49 AM5/9/08
to testng...@googlegroups.com
IAnnotationTransformers only work on @Test methods, not configuration methods.

I'll fix that shortly, but I have to introduce a new interface IAnnotationTransformer2 in order not to break existing clients:

public interface IAnnotationTransformer2 extends IAnnotationTransformer {
  public void transform(IConfiguration annotation, Class testClass,
      Constructor testConstructor, Method testMethod);
 
}

Then you can simply set setEnabled(true) on that method.

Would that fix your problem?

--
Cedric
--
Cédric

Andre

unread,
May 13, 2008, 3:18:53 AM5/13/08
to testng-users
Thank you,

Yes, that woud fix my problem. :-)

André

Raghu Nandan

unread,
Apr 9, 2014, 5:26:44 AM4/9/14
to testng...@googlegroups.com
Hi Cedric,

I am using IAnnotationTransformer2 as given below. I want to set alwaysRun on all methods annotated with @AfterClass. I want methods annotated with @AfterClass to run even if the @Test method fails. However, I don't find setAlwaysRun function in IConfigurationAnnotation. I can call testAnnotation.setEnabled (true) but this does not result in my @AfterClass methods to run when @Test fails. Please explain.

public class MyTransformer implements IAnnotationTransformer2
{
   @Override
   public void transform (IConfigurationAnnotation testAnnotation, Class testClass, Constructor testConstructor, Method testMethod)
   {
      if (testMethod.isAnnotationPresent(AfterClass.class))
      {
         // testAnnotation.setAlwaysRun (true)
      }
   }
}

Thanks,
Raghu

Krishnan Mahadevan

unread,
Apr 9, 2014, 12:52:05 PM4/9/14
to testng...@googlegroups.com
Raghu,

Please try coding your transformer's transform method as below:
        @Override
        public void transform(IConfigurationAnnotation annotation, Class testClass, Constructor testConstructor,
                Method testMethod) {
            if (annotation.getAfterTestClass()){
                ((ConfigurationAnnotation) annotation).setAlwaysRun(true);
            }
        }





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/


--
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 testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Raghu Nandan

unread,
Apr 10, 2014, 2:26:24 AM4/10/14
to testng...@googlegroups.com
Thanks a lot Krishnan!
Reply all
Reply to author
Forward
0 new messages