aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes problem using nested sysproperty in testng task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "problem using nested sysproperty in testng task " Watch "problem using nested sysproperty in testng task " New topic
Author

problem using nested sysproperty in testng task

prateek urmaliya
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
Hi All,

It needs some explanation ;

I am using testng to test an application against different env. (Dev, qa, uat, prod).

Now there are certain groups to be included and excluded. And env to be added and removed.

So I am using simple testng task like

<testng classpathref="project.class.path"

sourcedir="${test.src.dir}"

outputdir="${test.output}/${env}/${touch.time}"

groups="${groups.included}"

excludedgroups="${groups.excluded}"

verbose="2">

<jvmarg value="-Dtest.url=${java.naming.provider.url}"/>

<!--sysproperty key="test.url" value="${java.naming.provider.url}"/-->

<classfileset dir="${classes.dir}" includes="**/*.class"/> </testng>

I have one env.properties where I have defined all the provider.url and groups included\excluded information. env.list simply holds the env that I want my test to run against so that I need to change only env.list to include/exclude env.

And groupsincluded/groupsexcluded for changing the groups in that env.

That looks something like



env.list=jabberwocky.dev,jabberwocky.qa



all.test=foo_test,bar_test



jabberwocky.dev.provider.url=t3://localhost:7001

jabberwocky.dev.groupsincluded=foo_test

jabberwocky.dev.groupsexcluded=



jabberwocky.qa.provider.url=t3://localhost:7002

jabberwocky.qa.groupsincluded=bar_test

jabberwocky.qa.groupsexcluded=



jabberwocky.uat.provider.url=t3://localhost:7002

jabberwocky.uat.groupsincluded=${all.test}

jabberwocky.uat.groupsexcluded=



I am importing this file <property file="${test.src.dir}/conf/env.properties" /> in ant and

To iterate through these and run test against each server I am using antcontrib's foreach

<target name="run">

<foreach list="${env.list}" delimiter="," param="env" target="test" inheritall="true"/>

</target>



the test target simply executes the testng task where I set group and provider url information regarding the test to be run and also setting a system property with name test.url so that I can get it later to use in one of the test case.

<target name="test">

<!-- Get the properties ${name}.* -->

<propertycopy name="java.naming.provider.url" from="${env}.provider.url" silent="true"/>

<propertycopy name="groups.included" from="${env}.groupsincluded" silent="true"/>

<mkdir dir="${test.output}/${env}/${touch.time}"/>

<mkdir dir="${test.report}/${env}/${touch.time}"/>

<echo>touch.time=${touch.time}</echo>

<echo>groups.included=${groups.included}</echo>

<echo>java.naming.provider.url=${java.naming.provider.url}</echo>

<testng classpathref="project.class.path"

sourcedir="${test.src.dir}"

outputdir="${test.output}/${env}/${touch.time}"

groups="${groups.included}"

verbose="2"

>

<jvmarg value="-Dtest.url=${java.naming.provider.url}"/>

<!--sysproperty key="test.url" value="${java.naming.provider.url}"/-->

<classfileset dir="${classes.dir}" includes="**/*.class"/> </testng>

<echo>test.url=${test.url}</echo>

<antcall target="reports"/>

</target>

Now this test.url is being used in one of my test(webservice test)

To get the url for creating the port

String provider_url=System.getProperty("test.url");

Reporter.log(provider_url.replaceFirst("t3","http")+"/jabberwocky/jabberwocky?WSDL");



I am not able to get test.url in my test I tried sysproperty and jvmarg both but to no avail.



The other tests are running fine and I am getting result against each env based on the timestamp

<tstamp>

<format property="touch.time" pattern="MM_dd_yyyy_hh_mm_aa"/>

</tstamp>

I don't know whether I am missing something on ANT or TestNG or ant-contrib please help?

version ANT 1.6.5

testNG 5.1jdk1.4

ant-contrib-1.0b2
[ September 19, 2006: Message edited by: prateek urmaliya ]

this message brought to you by .... PIE! .... it's yummy! ;)
prateek urmaliya
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
I Cleaned I jarred it worked
BTW is there some better way of achieving the same.
Something that helps me to avoid adding another jar(antcontrib) to my already swelling classpath.
I tried parsing env. File and creating objects based on diif env with group and url info then accessing them but it was not that configurable.

Thanks,
Prateek
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem using nested sysproperty in testng task