[JVM] Passing Ant Value to Java

176 views
Skip to first unread message

theposob

unread,
May 17, 2013, 9:52:00 AM5/17/13
to cu...@googlegroups.com
I am currently running several tests via cucumber-jvm, and I am kicking them off via an ant script. I am passing values to the ant script via command line at run, which are then overriding my Cucumber.Options values. This is working fantastic, and allows me to select different feature files, and different scenarios with specific tags on the fly. My question is, can my actual java code access these values from the ant script. Anywhere in the javacode would be acceptable, but ideally my @Before method could access these values to properly setup my testing environment based on the tests being run. Thanks in advance for the support!

aslak hellesoy

unread,
May 17, 2013, 10:48:27 AM5/17/13
to Cucumber Users
On Fri, May 17, 2013 at 8:52 AM, theposob <max.sap...@coveros.com> wrote:
I am currently running several tests via cucumber-jvm, and I am kicking them off via an ant script. I am passing values to the ant script via command line at run

You mean you're defining JVM system properties on the command line using -D?
 
, which are then overriding my Cucumber.Options values. This is working fantastic, and allows me to select different feature files, and different scenarios with specific tags on the fly. My question is, can my actual java code access these values from the ant script.

This is really a question about Ant, not Cucumber. Rephrased:
When you say values, what exactly do you mean? JVM system properties? Ant <property> values?

Please see An't docs for the <java> task to learn how to pass JVM system properties to a java program launched from Ant.
If you fork, you have to pass them explicitly, if you don't fork, Ant and Cucumber will run in the same JVM and have access to the same system properties.

Aslak
 
Anywhere in the javacode would be acceptable, but ideally my @Before method could access these values to properly setup my testing environment based on the tests being run. Thanks in advance for the support!

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Max Saperstone

unread,
May 17, 2013, 10:53:37 AM5/17/13
to cu...@googlegroups.com
Aslak, thanks for the quick response, I'll checkout the ant docs and see what I can get from them. I put in some answer below, just to clarify in case anyone else has this question.


On Fri, May 17, 2013 at 10:48 AM, aslak hellesoy <aslak.h...@gmail.com> wrote:



On Fri, May 17, 2013 at 8:52 AM, theposob <max.sap...@coveros.com> wrote:
I am currently running several tests via cucumber-jvm, and I am kicking them off via an ant script. I am passing values to the ant script via command line at run

You mean you're defining JVM system properties on the command line using -D?

Correct 
 
, which are then overriding my Cucumber.Options values. This is working fantastic, and allows me to select different feature files, and different scenarios with specific tags on the fly. My question is, can my actual java code access these values from the ant script.

This is really a question about Ant, not Cucumber. Rephrased:
When you say values, what exactly do you mean? JVM system properties? Ant <property> values?

I mean the target argument values. E.g.: <arg value="${feature}"/>, and <arg value="--tags"/>            <arg value="${tags}"/> 

Please see An't docs for the <java> task to learn how to pass JVM system properties to a java program launched from Ant.
If you fork, you have to pass them explicitly, if you don't fork, Ant and Cucumber will run in the same JVM and have access to the same system properties.

I'm unsure what you mean by forking. Which I'll assume means I am not, just using the base functionality. Thanks for the reference.

Aslak
 
Anywhere in the javacode would be acceptable, but ideally my @Before method could access these values to properly setup my testing environment based on the tests being run. Thanks in advance for the support!

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Cukes" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cukes/3zrgof6rFFk/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to cukes+un...@googlegroups.com.

Max Saperstone

unread,
May 17, 2013, 11:03:13 AM5/17/13
to cu...@googlegroups.com
Just a quick update, this was much simpler than I thought. 
I have set forked to true, so I had to explicitly set the value. That section of my build.xml file looks something like the below:
      <java classname="cucumber.api.cli.Main" fork="true" failonerror="false" resultproperty="cucumber.exitstatus">
            <classpath refid="classpath"/>
            <arg value="${feature}"/>
            <arg value="--tags"/>
            <arg value="${tags}"/>
            <sysproperty key="tags" value="${tags}"/>
      </java>
Then to access this value, I have something like the below:
@Before //performed before anything is done
public void setup() throws SAXException, IOException {
               System.out.println( "tags: " + System.getProperty( "tags" ) );
         }

Thanks for the pointers on where to look!

Reply all
Reply to author
Forward
0 new messages