Invoke annotation Transformer programmatically

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

Invoke annotation Transformer programmatically

nguyenki
Hi,
 I'm a newbie in TestNG. Sorry if this question has been posted.
 I would like to use the annotation Transformer to modify the variable invocationCount,  i'm using Maven to build my app.
 For the moment, i used the suggestion in the testNG documentation.
 
public class MyTransformer implements IAnnotationTransformer {
private TestConfig config;
private int number;
public MyTransformer() throws FileNotFoundException {
config = new TestConfig(true);
number = config.getInfoFromFileURI().size();
}
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
// TODO Auto-generated method stub
if ("BechMarkTestAllLinks".equals(testMethod.getName())) {
annotation.setInvocationCount(number);
}
}
}

I wrote another class to invoke this annotation:
public class VerifyAnnotationTransformer {

 @Test(groups = "transform")
   public void setUpTransformerClass() throws FileNotFoundException {
    TestNG tng = new TestNG();
    tng.setVerbose(0);
    tng.setAnnotationTransformer(new MyTransformer());
    tng.setTestClasses( new Class[] { AppTest.class, KPITest.class, BenchMarkTest.class });
    Reporter.log("Modify invocationCount");
    TestListenerAdapter tla = new TestListenerAdapter();
    tng.addListener(tla);
    tng.run();
    }
}

Here is the method that i want to modify thi value of invocationCount:
public class AppTest {
        @Test(dependsOnGroups = {"Login"}, groups = {"FuncTest", "PageUser", "URI"}, invocationCount = 1)
public void BechMarkTestAllLinks() throws Exception {

}
}

--
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: Invoke annotation Transformer programmatically

nguyenki
i know that there's another way to invoke this annotation using Ant, but i'm using Maven.
Any suggestions.
Thanks.

On Fri, Jul 27, 2012 at 3:42 PM, nguyenkim thuat <[hidden email]> wrote:
Hi,
 I'm a newbie in TestNG. Sorry if this question has been posted.
 I would like to use the annotation Transformer to modify the variable invocationCount,  i'm using Maven to build my app.
 For the moment, i used the suggestion in the testNG documentation.
 
public class MyTransformer implements IAnnotationTransformer {
private TestConfig config;
private int number;
public MyTransformer() throws FileNotFoundException {
config = new TestConfig(true);
number = config.getInfoFromFileURI().size();
}
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
// TODO Auto-generated method stub
if ("BechMarkTestAllLinks".equals(testMethod.getName())) {
annotation.setInvocationCount(number);
}
}
}

I wrote another class to invoke this annotation:
public class VerifyAnnotationTransformer {

 @Test(groups = "transform")
   public void setUpTransformerClass() throws FileNotFoundException {
    TestNG tng = new TestNG();
    tng.setVerbose(0);
    tng.setAnnotationTransformer(new MyTransformer());
    tng.setTestClasses( new Class[] { AppTest.class, KPITest.class, BenchMarkTest.class });
    Reporter.log("Modify invocationCount");
    TestListenerAdapter tla = new TestListenerAdapter();
    tng.addListener(tla);
    tng.run();
    }
}

Here is the method that i want to modify thi value of invocationCount:
public class AppTest {
        @Test(dependsOnGroups = {"Login"}, groups = {"FuncTest", "PageUser", "URI"}, invocationCount = 1)
public void BechMarkTestAllLinks() throws Exception {

}
}

--
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: Invoke annotation Transformer programmatically

⇜Krishnan Mahadevan⇝
Create a suite file. 
Add you annotation transformer as a listener in the suite file. 
Add surefire-plugin to your pom file. 

That should do!

But since you are saying that you want to invoke your transformer via code then you should ideally speaking, write a main method, instantiate TestNG add the transformer, create your suite, test via the api and do it. 

I dont think it makes sense for you to couple TestNG API calls from within TestNG annotated methods. Atleast I fail to understand its relevance!

With respect to invoking it from maven you should be doing as recommended in this thread : http://stackoverflow.com/questions/1089285/maven-run-project

Hope that helps!

On Friday, July 27, 2012, nguyenkim thuat wrote:
i know that there's another way to invoke this annotation using Ant, but i'm using Maven.
Any suggestions.
Thanks.

On Fri, Jul 27, 2012 at 3:42 PM, nguyenkim thuat <<a href="javascript:_e({}, &#39;cvml&#39;, &#39;kimthuatnguyenensimagfr@gmail.com&#39;);" target="_blank">kimthuatnguyenensimagfr@...> wrote:
Hi,
 I'm a newbie in TestNG. Sorry if this question has been posted.
 I would like to use the annotation Transformer to modify the variable invocationCount,  i'm using Maven to build my app.
 For the moment, i used the suggestion in the testNG documentation.
 
public class MyTransformer implements IAnnotationTransformer {
private TestConfig config;
private int number;
public MyTransformer() throws FileNotFoundException {
config = new TestConfig(true);
number = config.getInfoFromFileURI().size();
}
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
// TODO Auto-generated method stub
if ("BechMarkTestAllLinks".equals(testMethod.getName())) {
annotation.setInvocationCount(number);
}
}
}

I wrote another class to invoke this annotation:
public class VerifyAnnotationTransformer {

 @Test(groups = "transform")
   public void setUpTransformerClass() throws FileNotFoundException {
    TestNG tng = new TestNG();
    tng.setVerbose(0);
    tng.setAnnotationTransformer(new MyTransformer());
    tng.setTestClasses( new Class[] { AppTest.class, KPITest.class, BenchMarkTest.class });
    Reporter.log("Modify invocationCount");
    TestListenerAdapter tla = new TestListenerAdapter();
    tng.addListener(tla);
    tng.run();
    }
}

Here is the method that i want to modify thi value of invocationCount:
public class AppTest {
        @Test(dependsOnGroups = {"Login"}, groups = {"FuncTest", "PageUser", "URI"}, invocationCount = 1)
public void BechMarkTestAllLinks() throws Exception {

}
}

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to <a href="javascript:_e({}, &#39;cvml&#39;, &#39;testng-users@googlegroups.com&#39;);" target="_blank">testng-users@....
To unsubscribe from this group, send email to <a href="javascript:_e({}, &#39;cvml&#39;, &#39;testng-users%2Bunsubscribe@googlegroups.com&#39;);" target="_blank">testng-users+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


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

--
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: Invoke annotation Transformer programmatically

nguyenki
On Sat, Jul 28, 2012 at 5:08 AM, Krishnan Mahadevan <[hidden email]> wrote:
Create a suite file. 
Add you annotation transformer as a listener in the suite file. 
Add surefire-plugin to your pom file. 

That should do
That's true, i did the same thing like you said. I give the code here for someone who is stacked by this problem.
 I just have to add the listener in the testng.xml
 
   <listeners>
    <listener class-name="com.FiftyFive.app.MyTransformer"/>
  </listeners>

and add the surefire-plugin to the pom file:
 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.5</version>
        <configuration>
           <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
         </suiteXmlFiles>
        </configuration>
      </plugin>
 

But since you are saying that you want to invoke your transformer via code then you should ideally speaking, write a main method, instantiate TestNG add the transformer, create your suite, test via the api and do it. 
i didn't really mean this, i just want to invoke the transformer one time, so the solution above is perfect to me.
Anyway, thanks you a lot for the solution.
Best regards.
 

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