how to pass the @testng.test invocationCount="5" through the properties file or xml file

3,639 views
Skip to first unread message

ram

unread,
Oct 17, 2005, 4:10:43 AM10/17/05
to testng-users
Hello,
my problem is like i want to excute method more then one for that i
use
/**
*@testng.test invocationCount="10"
*/
but i want to change the value inplace of 10 to 15 i have to again
compile the java file and then run it..
but i want this value as the configurable like from testing.xml or i
like to call one properties file in that i put count="10"
then in the test file like that
/**
*@testng.test invocationCount="count"
*/
this count value i load it from some propeerties file..
but it is not working.. is i m doing right?
any body have any idea on that how to pass the value
" invocationCount" value from other file my motto is to remove the
headech of again compiling the test file in place of that just cahnge
the value of this "invocationCount" and run only .


plz give me suggestion how to achive this.???

one more problem i face like
i have 5 method in the testing file (method1,method2...method5)..
and i want to excute method in the order
method3,method1,method4,method2,method5 and also no of invocation of
the methods like method5 have 3 times method2 have 8 times.

i done it like that


/**
*@testng.test invocationCount="3"
*/
method5()
{
}
/**
*@testng.test invocationCount="8"
*/
method2()
{
}
i apply beforecount="method1 " for sequence of excution the method .but
from this i achive the sequence of excution but ca't get the no of the
excution coz when same method call again due to invocationCount="3"
before method again calls..
my motto is to achive
like this scenario
method3 invocationCount="1"
method1 invocationCount="1"
method4 invocationCount="1"
method2 invocationCount="3"
method5 invocationCount="8"

but i cant find the solution for this..

have any body idea this..???
plz give me suggestion

thanks in advance
ram

Alexandru Popescu

unread,
Oct 17, 2005, 5:28:35 AM10/17/05
to testng...@googlegroups.com
#: ram changed the world a bit at a time by saying on 10/17/2005 10:10 AM :#
> Hello,
> my problem is like i want to excute method more then one for that i
> use
> /**
> *@testng.test invocationCount="10"
> */
> but i want to change the value inplace of 10 to 15 i have to again
> compile the java file and then run it..
> but i want this value as the configurable like from testing.xml or i
> like to call one properties file in that i put count="10"
> then in the test file like that
> /**
> *@testng.test invocationCount="count"
> */
> this count value i load it from some propeerties file..
> but it is not working.. is i m doing right?
> any body have any idea on that how to pass the value
> " invocationCount" value from other file my motto is to remove the
> headech of again compiling the test file in place of that just cahnge
> the value of this "invocationCount" and run only .
>
>
> plz give me suggestion how to achive this.???
>

Currently you cannot do it in this form. Probably a way to do it is like:

define a @Test method that receives the invocation count as the parameter. Inside a loop call a
method for "invocation count" times.
Even if in the first place this scenario seems like it should be supported, I have found myself
wondering the following:

if method A depends on method B, than why should the 4th run of method A not trigger a run for method B?

I guess the only answer for this is because A doesn't really depend on B. At this level needing an
order to your test methods is a smell ;-).

hope this clarifies it,

./alex
--
.w( the_mindstorm )p.

ram

unread,
Oct 17, 2005, 4:50:17 AM10/17/05
to testng-users
Hi Alex,
thanks for giving quick reply..i got ur answer but it is not solving my
problem.....

first problem that i mention is i excute more then once that method..
coz i want to generate data in the database...
for that i call it no of times.. if i call in the loop then it takes
more times...!!!!
my motto is that generate bulk data in short span of times.. if i
excute it in the loop then it is taking more times...
is there any other solution through TestNG that i can generate data in
the configurable manner...
like suppose i enter usename =user1..user2....user1000 for that i have
one method createUser() method (it create user) for that i use the
TestNG and i excute createUser() 1000 times.. for 1000 users...

and second problem is also related to that i excute createUsers() 1000
times but i want to initilize the properties by excute other method
initilize() only one times..this is my problem and my motto..


plz give me the suggestion how to solve this problem..

thanks in advance....
ram....

Alexandru Popescu

unread,
Oct 17, 2005, 5:59:36 AM10/17/05
to testng...@googlegroups.com
#: ram changed the world a bit at a time by saying on 10/17/2005 10:50 AM :#
> Hi Alex,
> thanks for giving quick reply..i got ur answer but it is not solving my
> problem.....
>
> first problem that i mention is i excute more then once that method..
> coz i want to generate data in the database...
> for that i call it no of times.. if i call in the loop then it takes
> more times...!!!!

How? Isn't it the same: either TestNG or you can call a method a number of times. The execution time
will be almost the same:

@Test(invocationCount=100)
public void createUser() {
}

=> will be invoked by TestNG 100 times

@Test
@Parameter("userCount")
public void callCreateUser(int userCount) {
for(int i = 0; i < userCount; i++) {
createUser(i);
}
}

protected void createUser(int userNo) {
}

=> will create 100 users. The execution time is almost the same: in the first case you have 100
method calls (done through reflection), in the 2 you have 101 method calls from which only 1 is doen
through reflection. Which one do you think will run faster? Which one is fitting the scenario you
are describing?

> my motto is that generate bulk data in short span of times.. if i
> excute it in the loop then it is taking more times...
> is there any other solution through TestNG that i can generate data in
> the configurable manner...
> like suppose i enter usename =user1..user2....user1000 for that i have
> one method createUser() method (it create user) for that i use the
> TestNG and i excute createUser() 1000 times.. for 1000 users...
>
> and second problem is also related to that i excute createUsers() 1000
> times but i want to initilize the properties by excute other method
> initilize() only one times..this is my problem and my motto..
>
>

I am not sure what the aboves means. You are creating 100 users and than only 1 of them would have
properties set? Than again the scenario described above will solve your problem.

> plz give me the suggestion how to solve this problem..
>
> thanks in advance....
> ram....
>
>

hth,

ram

unread,
Oct 17, 2005, 5:18:24 AM10/17/05
to testng-users
thanks for quick reply.......
yes it is almost he same thing..
but my problem is not solve....i want to achive it minmum time ...so
how to put the threading ... or other way to achive it less then that
times it takes in the loop....
TestNg have the property that threading <suite name="My
suite" parallel="true" thread-count="5">
but i think so it is use when u have the multiple method...
my motto is to generate bulk data in min time through testng ....

is there any other solution that fix my problem..??

plz suggest me...

thanks in advance ..

ram...

Alexandru Popescu

unread,
Oct 17, 2005, 7:03:10 AM10/17/05
to testng...@googlegroups.com
#: ram changed the world a bit at a time by saying on 10/17/2005 11:18 AM :#
the threading will not improve your general time, as you will move the problem into a concurrential
insert env, which in fact will increase the execution time (the db needs to manage multiple
concurrent transactions).

however, afaik TestNG is a testing framework and not a bulk db enabler ;-).

ram

unread,
Oct 17, 2005, 7:52:02 AM10/17/05
to testng-users
thanks i will do it throw hardcode the InvocatioCount
but when i hardcode it i face new problem...

i put java annotation jdk1.4 for TestNG

i pass both paramter and invocationCount=5 like that
/**
*@testng.test invocationCount="5"
*@testng.parameters value="user-name group-name "
*/

i pass two paramter(username and groupname ) and invocationcount ="5"

but it is excuted only once...

any idea.. about that why it is excuted only once it should excuted 5
times...

plz give me suggestion..
thanks in advance
ram....

Alexandru Popescu

unread,
Oct 17, 2005, 9:04:14 AM10/17/05
to testng...@googlegroups.com
#: ram changed the world a bit at a time by saying on 10/17/2005 1:52 PM :#
I am not sure I can follow you. Please provide you code and testng.xml (or command line args) so
that I can replay it.

Cédric Beust ♔

unread,
Oct 17, 2005, 10:03:11 AM10/17/05
to testng...@googlegroups.com
On 10/17/05, ram <friend...@gmail.com> wrote:

Hello,
my problem is like i want to excute method more then one  for that i
use
     /**
         *@testng.test invocationCount="10"
     */
but i want to change the value inplace of 10 to  15 i have to again
compile the java file and then run it..
but i want this value as the configurable like from testing.xml or i
like to call one properties file in that i put count="10"
then in the test file like that
/**
*@testng.test invocationCount="count"
*/

You can do this:

/**
*@testng.test invocationCount="${count}"
*/

and then define the value in testng.xml:

<parameter name="count" value="5" />


one more problem i face like
i have 5 method in the testing file (method1,method2...method5)..
and i want to excute method in the order
method3,method1,method4,method2,method5 and also no of invocation of
the methods like method5 have 3 times method2 have 8 times.

Just add a dependsOnMethods attribute

/**
  * @testng.test dependsOnMethods = "method1"
  */
public void method2() { ... }


--
Cédric

ram

unread,
Oct 18, 2005, 12:54:06 AM10/18/05
to testng-users
hello Credic,
i apply ur suggestion but it is throwing the exception .
my code like

/**
*@testng.test invocationCount="${count}"

*/
and then define the value in testng.xml:

<parameter name="count" value="5" />

exception is throwing when i run this..
===============================================
userprofileaudit.UsersTestNG
Total tests run: 0, Failures: 0, Skips: 0
===============================================

java.lang.NumberFormatException: For input string: "${count}"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.<init>(Unknown Source)
at
org.testng.internal.jdk14.AnnotationHelper.createTestMap(AnnotationHelper.java:292)
at
org.testng.internal.jdk14.AnnotationHelper.createAnnotation(AnnotationHelper.java:153)
at
org.testng.internal.jdk14.QDoxAnnotationFinder.createMethodAnnotation(QDoxAnnotationFinder.java:249)
at
org.testng.internal.jdk14.QDoxAnnotationFinder.findAnnotation(QDoxAnnotationFinder.java:157)
at
org.testng.internal.jdk14.QDoxAnnotationFinder.findAnnotation(QDoxAnnotationFinder.java:168)
at
org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:158)
at
org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:49)
at org.testng.TestRunner.initMethods(TestRunner.java:240)
at org.testng.TestRunner.init(TestRunner.java:188)
at org.testng.TestRunner.init(TestRunner.java:160)
at org.testng.TestRunner.<init>(TestRunner.java:116)
at
org.testng.eclipse.runner.RemoteTestNG$2.newTestRunner(RemoteTestNG.java:81)
at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:347)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:151)
at org.testng.SuiteRunner.run(SuiteRunner.java:117)
at org.testng.eclipse.runner.RemoteTestNG.run(RemoteTestNG.java:99)
at org.testng.eclipse.runner.RemoteTestNG.main(RemoteTestNG.java:138)
Exception in thread "main"


i changed the parameter value
<parameter name="count" value=5 />
but is not working it required the string value..
i changed in the code also

/**
*@testng.test invocationCount=${count}

*/
but it not accepting..

any more idea abut that how to solve this..

thanks in advance..

ram.

Cédric Beust ♔

unread,
Oct 18, 2005, 1:29:15 AM10/18/05
to testng...@googlegroups.com
Ram,

I think you found a bug, I'll look into it shortly.

--
Cedric


On 10/17/05, ram <friend...@gmail.com > wrote:

hello Credic,
i apply ur suggestion but it is throwing the exception .
my code like
/**
*@testng.test invocationCount="${count}"

*/
and then define the value in testng.xml:

<parameter name="count" value="5" />

exception is throwing when i run this..
===============================================
userprofileaudit.UsersTestNG
Total tests run: 0, Failures: 0, Skips: 0
===============================================

java.lang.NumberFormatException: For input string: "${count}"
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.<init>(Unknown Source)
        at
org.testng.internal.jdk14.AnnotationHelper.createTestMap (AnnotationHelper.java:292)

        at
org.testng.internal.jdk14.AnnotationHelper.createAnnotation(AnnotationHelper.java:153)
        at
org.testng.internal.jdk14.QDoxAnnotationFinder.createMethodAnnotation(QDoxAnnotationFinder.java :249)
        at
org.testng.internal.jdk14.QDoxAnnotationFinder.findAnnotation(QDoxAnnotationFinder.java:157)
        at
org.testng.internal.jdk14.QDoxAnnotationFinder.findAnnotation(QDoxAnnotationFinder.java:168)
        at
org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:158)
        at
org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:49)
        at org.testng.TestRunner.initMethods (TestRunner.java:240)

        at org.testng.TestRunner.init(TestRunner.java:188)
        at org.testng.TestRunner.init(TestRunner.java:160)
        at org.testng.TestRunner.<init>(TestRunner.java:116)
        at
org.testng.eclipse.runner.RemoteTestNG$2.newTestRunner(RemoteTestNG.java:81)
        at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:347)
        at org.testng.SuiteRunner.privateRun (SuiteRunner.java:151)

        at org.testng.SuiteRunner.run(SuiteRunner.java:117)
        at org.testng.eclipse.runner.RemoteTestNG.run(RemoteTestNG.java:99)
        at org.testng.eclipse.runner.RemoteTestNG.main (RemoteTestNG.java:138)

Exception in thread "main"


i changed the parameter value
<parameter name="count" value=5 />
but is not working it required the string value..
i changed in the code also

/**
*@testng.test invocationCount=${count}

*/
but it not accepting..

any more idea abut that how to solve this..

thanks in advance..

ram.




--
Cédric

ram

unread,
Oct 20, 2005, 1:09:57 AM10/20/05
to testng-users
Hello Cedric,
any luck on the how to pass the invocationCount to the test class from
testing.xml .
thanks
ram...

Cédric Beust ♔

unread,
Oct 20, 2005, 11:14:07 AM10/20/05
to testng...@googlegroups.com
Ram,

On 10/19/05, ram <friend...@gmail.com> wrote:

Hello Cedric,
any luck on the how to pass the invocationCount to the test class from
testing.xml .

I haven't had the time to look at it but I should find some time in the next few days.  You're on top of my TODO list, so I'm not forgetting you :-)


--
Cédric

Cédric Beust ♔

unread,
Oct 21, 2005, 1:36:51 PM10/21/05
to testng...@googlegroups.com
Hi Ram,

Well, actually there's a slight problem and parameter substitution is not going to work in this case, because this attribute is typed:  it's an integer.

You are not seeing this since you are using the JDK 1.4 version and everything is a String, but the annotation is really:

  @Test(invocationCount = 10, successPercentage = 80)

...  and right now, I can't find any good way of being able to replace 10 with the value of a parameter...

Any suggestion?

--
Cedric


On 10/17/05, ram <friend...@gmail.com> wrote:

hello Credic,
i apply ur suggestion but it is throwing the exception .
my code like
/**
*@testng.test invocationCount="${count}"

*/
and then define the value in testng.xml:

<parameter name="count" value="5" />

exception is throwing when i run this..
===============================================
userprofileaudit.UsersTestNG
Total tests run: 0, Failures: 0, Skips: 0
===============================================

java.lang.NumberFormatException: For input string: "${count}"
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.<init>(Unknown Source)
        at
org.testng.internal.jdk14.AnnotationHelper.createTestMap (AnnotationHelper.java:292)

        at
org.testng.internal.jdk14.AnnotationHelper.createAnnotation(AnnotationHelper.java:153)
        at
org.testng.internal.jdk14.QDoxAnnotationFinder.createMethodAnnotation(QDoxAnnotationFinder.java :249)
        at
org.testng.internal.jdk14.QDoxAnnotationFinder.findAnnotation(QDoxAnnotationFinder.java:157)
        at
org.testng.internal.jdk14.QDoxAnnotationFinder.findAnnotation(QDoxAnnotationFinder.java:168)
        at
org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:158)
        at
org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:49)
        at org.testng.TestRunner.initMethods (TestRunner.java:240)

        at org.testng.TestRunner.init(TestRunner.java:188)
        at org.testng.TestRunner.init(TestRunner.java:160)
        at org.testng.TestRunner.<init>(TestRunner.java:116)
        at
org.testng.eclipse.runner.RemoteTestNG$2.newTestRunner(RemoteTestNG.java:81)
        at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:347)
        at org.testng.SuiteRunner.privateRun (SuiteRunner.java:151)

        at org.testng.SuiteRunner.run(SuiteRunner.java:117)
        at org.testng.eclipse.runner.RemoteTestNG.run(RemoteTestNG.java:99)
        at org.testng.eclipse.runner.RemoteTestNG.main (RemoteTestNG.java:138)

Exception in thread "main"


i changed the parameter value
<parameter name="count" value=5 />
but is not working it required the string value..
i changed in the code also

/**
*@testng.test invocationCount=${count}

*/
but it not accepting..

any more idea abut that how to solve this..

thanks in advance..

ram.




--
Cédric

Cédric Beust ♔

unread,
Oct 23, 2005, 7:46:26 PM10/23/05
to testng...@googlegroups.com
On 10/21/05, Cédric Beust ♔ <cbe...@google.com> wrote:
Hi Ram,

Well, actually there's a slight problem and parameter substitution is not going to work in this case, because this attribute is typed:  it's an integer.

You are not seeing this since you are using the JDK 1.4 version and everything is a String, but the annotation is really:

  @Test(invocationCount = 10, successPercentage = 80)

...  and right now, I can't find any good way of being able to replace 10 with the value of a parameter...

Any suggestion?

I thought about it more, and here is a possibility:

<parameter name="invocation" value="10" />
<parameter name="sp" value="80" />

@Test(invocationCountVar = "invocation", successPercentageVar = "sp")

Basically, just using the same attribute name as above but adding "Var", and in this case, the value will be fetched from testng.xml.

What do you think?

--
Cédric

Alexandru Popescu

unread,
Oct 24, 2005, 2:31:35 PM10/24/05
to testng...@googlegroups.com
#: Cédric Beust ♔ changed the world a bit at a time by saying on 10/24/2005 1:46 AM :#
I am not sure if this is not bringing the @Test annotation too far (too many attributes). However,
it looks like the only possible solution with JDK1.5 annotations.

Anna

unread,
Mar 14, 2017, 8:25:59 AM3/14/17
to testng-users
Hi Cédric,
I am wondering if this useful feature was ever implemented? 

thanks and best regards,
Anna

⇜Krishnan Mahadevan⇝

unread,
Mar 14, 2017, 9:43:46 AM3/14/17
to testng...@googlegroups.com
Anna,

You have revived a really old TestNG thread.
You might want to make use of IAnnotationTransformer, which provides a much more easier way of altering any of the @Test annotations attributes in Runtime.
  • See here for some general documentation about Annotation transformer.
  • See here for javadocs.
  • See here for some samples.
  • See my blog post here to get introduced to the concept of Listeners in TestNG

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

Reply all
Reply to author
Forward
0 new messages