Running tags from maven and JUnit

7,634 views
Skip to first unread message

Svante

unread,
Jan 16, 2012, 9:51:57 AM1/16/12
to Cukes
Hi,
I'm using cucumber-jvm, running features with maven (via Jenkins) and
JUnit in Eclipse and I'm trying to add tags to my features and run
specific sets of features with specific tags.
How do I specify that I wish to run specific tagged features in maven/
Jenkins and JUnit in Eclipse?

Sorry if the question seems trivial, I searched this forum and Google
thoroughly to no avail.

/Svante

aslak hellesoy

unread,
Jan 16, 2012, 11:25:45 AM1/16/12
to cu...@googlegroups.com
On Mon, Jan 16, 2012 at 2:51 PM, Svante <svante...@gmail.com> wrote:
> Hi,
> I'm using cucumber-jvm, running features with maven (via Jenkins) and
> JUnit in Eclipse and I'm trying to add tags to my features and run
> specific sets of features with specific tags.
> How do I specify that I wish to run specific tagged features in maven/
> Jenkins and JUnit in Eclipse?
>

You can specify tags using the @Feature annotation:

@RunWith(Cucumber.class)
@Feature(value="your/package", tags={"@focus"})

We will probably rename the @Feature annotation to @Opts in the next
release. Since the JUnit runner now can run a whole bunch of features
(no need to have a class per feature), it makes more sense to use this
annotation to pass general options to Cucumber. -Just like you can
when you are using the command-line interface.

Aslak

> Sorry if the question seems trivial, I searched this forum and Google
> thoroughly to no avail.
>
> /Svante
>

> --
> 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 http://groups.google.com/group/cukes?hl=en.
>

Svante

unread,
Jan 17, 2012, 5:09:06 AM1/17/12
to Cukes
Thank you for your reply,

Sorry, but I'm still a little confused. With regard to:

@RunWith(Cucumber.class)
@Feature(value="your/package", tags={"@focus"})

Where do I put it? And is it to mark a feature with the @focus tag or
is it to run features with the @focus tag?
Does it work for both maven and JUnit? What if I want to run different
tags with mavne than with JUnit?

And do I still mark features with "@[tag]" in .feature files like
this:

@focus
Feature: test-feature
Given ...
When ...
Then ...

?

Sorry for all the questions, I'm trying hard to understand :)

/Svante

On Jan 16, 5:25 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:

aslak hellesoy

unread,
Jan 17, 2012, 5:25:06 AM1/17/12
to cu...@googlegroups.com
On Tue, Jan 17, 2012 at 10:09 AM, Svante <svante...@gmail.com> wrote:
> Thank you for your reply,
>
> Sorry, but I'm still a little confused. With regard to:
>
> @RunWith(Cucumber.class)
> @Feature(value="your/package", tags={"@focus"})
>
> Where do I put it?

On an empty test class. Like this:
https://github.com/cucumber/cucumber-jvm/blob/master/picocontainer/src/test/java/cucumber/runtime/java/picocontainer/RunCukesTest.java

> And is it to mark a feature with the @focus tag or
> is it to run features with the @focus tag?

That would run all features that are tagged with @focus

> Does it work for both maven and JUnit? What if I want to run different
> tags with mavne than with JUnit?
>

Cucumber doesn't know what launched JUnit (and neither does JUnit). So
it works with anything that can run a JUnit test, i.e. Ant, Maven,
your IDE...

> And do I still mark features with "@[tag]" in .feature files like
> this:
>
> @focus
> Feature: test-feature
>    Given ...
>    When ...
>    Then ...
>

Yes

Svante

unread,
Jan 30, 2012, 4:27:02 AM1/30/12
to Cukes
Thank you very much for the help.

For future reference:
To run all tags with
(Tested on Windows 7, with JUnit and Maven as test runners, and Java
as test class language)
1. Make sure you are running cucumber-jvm version RC11 or later.
2. Make a new RunMyTag.java file and put in the following: (name of
java file is not important)

package my.package.here //put in your own package
import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Feature(value = ".", tags = { "@my-tag-here" }) //put the tag you
want to run where it says "my-tag-here". value = "." means that you
want cucumber to look in all feature files for your tag, and run the
ones it find.
public class RunMyTag {
// Do nothing. This file just run features with a specific tag
(run me as JUnit test)
}

3. Run the class as a JUnit test class, and you should be golden.

To run the test class with Maven configure the surefire plugin (or
failsafe if you use that) to run the RunMyTag class as test.
This can be done in the pom.xml with:

<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<includes>
<include>**/RunMyTag.java</include>
</includes>
</configuration>
</plugin>
</plugins>

Usually you want to easily change between what tags you run, or if you
run all features, without editing the pom.xml. This can be done with
Maven profiles (see ).
Example:

<profile>
<id>RunMyTag</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<includes>
<include>**/RunMyTag.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

To activate the profile, in command prompt run: maven -P RunMyTag
verify
"verify" is just the goal, you can use any other goal(s) that activate
the surefire plugin.
The point is then that you can make as many test classes and profiles
as you have tags. And they can be run individually from maven.

If any of you know other or better ways of doing this, please share :)

Regards,
Svante

Copyright notice:
The author has placed this work in the Public Domain, thereby
relinquishing all copyrights. Everyone is free to use, modify,
republish, sell or give away this work without prior consent from
anybody.
This documentation is provided on an “as is” basis, without warranty
of any kind. Use at your own risk! Under no circumstances shall the
author(s) or contributor(s) be liable for damages resulting directly
or indirectly from the use or non-use of this documentation.
- so, feel free you use this in any way you wish.

On Jan 17, 11:25 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> On Tue, Jan 17, 2012 at 10:09 AM, Svante <svantetob...@gmail.com> wrote:
> > Thank you for your reply,
>
> > Sorry, but I'm still a little confused. With regard to:
>
> > @RunWith(Cucumber.class)
> > @Feature(value="your/package", tags={"@focus"})
>
> > Where do I put it?
>
> On an empty test class. Like this:https://github.com/cucumber/cucumber-jvm/blob/master/picocontainer/sr...

Paolo Ambrosio

unread,
Jan 30, 2012, 9:04:57 AM1/30/12
to cu...@googlegroups.com
On Mon, Jan 30, 2012 at 10:27 AM, Svante <svante...@gmail.com> wrote:

> To run the test class with Maven configure the surefire plugin (or
> failsafe if you use that) to run the RunMyTag class as test.
> This can be done in the pom.xml with:
>
>                <plugins>
>                    <plugin>
>                        <artifactId>maven-surefire-plugin</artifactId>

> ...

I usually run cucumber features with the maven-failsafe-plugin
(http://maven.apache.org/plugins/maven-failsafe-plugin/) bound to the
integration-test phase. As it says in its web page, "The Failsafe
Plugin is designed to run integration tests while the Surefire Plugins
is designed to run unit tests."

This is an extract of my pom.xml:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>

<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>

<include>unit/**/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>

<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>

<include>component/**/*.java</include>

<include>specification/functional/*.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>

<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

Tests in the package hierarchies unit and component are plain JUnit
tests, instead those in the specification.functional hierarchy are run
with the Cucumber runner like in your project (yes, I use non-standard
package hierarchies for tests).

I don't know if it makes sense :-)

--
Paolo

Bill Ross

unread,
Jan 30, 2012, 12:43:55 PM1/30/12
to cu...@googlegroups.com
This example seems to indicate that with cuke-jvm, one needs an
empty class with a tag in it in order to use a tag to select tests
to run? And that class needs to be called out explicitly in pom.xml?

I have been hesitant to get into cuke-jvm since it sounds like
tests somehow need to be bound to JUnit classes, which sounds like
more overhead than cuke4duke (which we've been using) has. E.g.
with cuke4duke I can select tags on the mvn cmd line with no
hardwired profiles. (Of course I know cuke4duke is EOL'd.)

If anyone would care to compare/contrast cuke-jvm with cuke4duke and
jBehave, I'd appreciate it.

Thanks,
Bill

Aslak Hellesøy

unread,
Jan 30, 2012, 1:08:56 PM1/30/12
to cu...@googlegroups.com
On Jan 30, 2012, at 17:43, Bill Ross <ro...@cgl.ucsf.edu> wrote:

> This example seems to indicate that with cuke-jvm, one needs an
> empty class with a tag in it in order to use a tag to select tests
> to run?

Cucumber-JVM has 2 different runners. A JUnit runner and a Command Lin
Interface (CLI) runner.

The JUnit runner requires a JUnit test class, as that is what JUnit
needs to run anything.

The CLI runner does not require a JUnit class. See the
jruby/jython/picocontainer modules' pom.xml for examples.

> And that class needs to be called out explicitly in pom.xml?
>

No it does not. Maven automatically runs all JUnit tests (including
those annotated with @RunWith(Cucumber.class)) as long as you follow
Maven's naming conventions.

> I have been hesitant to get into cuke-jvm since it sounds like
> tests somehow need to be bound to JUnit classes, which sounds like
> more overhead than cuke4duke (which we've been using) has.

You're misinformed. And if you choose to use the JUnit runner, a
single class is sufficient to run all features.

I wouldn't call a single empty class much overhead.

> E.g.
> with cuke4duke I can select tags on the mvn cmd line with no
> hardwired profiles.

The CLI runner lets you do the same.

> (Of course I know cuke4duke is EOL'd.)
>
> If anyone would care to compare/contrast cuke-jvm with cuke4duke and
> jBehave, I'd appreciate it.
>

That would be great!

Aslak

Svante

unread,
Jan 31, 2012, 5:23:14 AM1/31/12
to Cukes
> > E.g.
> > with cuke4duke I can select tags on the mvn cmd line with no
> > hardwired profiles.
>
> The CLI runner lets you do the same.
>

I have looked at the pom.xml for cucumber-jvm jython, jruby and
picocontainer. The only CLI switches I see are -S, --dotcucumber, --
format and --glue.
I don't see how any of them have anything to do with cucumber tags.

Is it really possible to run only specific tagged features from the
Maven CLI? (without Maven profiles, or other specific pom.xml config)
If so, how?

On Jan 30, 7:08 pm, Aslak Hellesøy <aslak.helle...@gmail.com> wrote:

aslak hellesoy

unread,
Jan 31, 2012, 5:31:58 AM1/31/12
to cu...@googlegroups.com
On Tue, Jan 31, 2012 at 10:23 AM, Svante <svante...@gmail.com> wrote:
>> > E.g.
>> > with cuke4duke I can select tags on the mvn cmd line with no
>> > hardwired profiles.
>>
>> The CLI runner lets you do the same.
>>
>
> I have looked at the pom.xml for cucumber-jvm jython, jruby and
> picocontainer. The only CLI switches I see are -S, --dotcucumber, --
> format and --glue.
> I don't see how any of them have anything to do with cucumber tags.
>

https://github.com/cucumber/cucumber-jvm/blob/fa4841b14c0f007190a7810dbb7e65cd4d8a6dda/core/src/main/java/cucumber/cli/Main.java#L52

It just isn't used in the poms.

> Is it really possible to run only specific tagged features from the
> Maven CLI?

Sure, you could `mvn -Dtags=@foo` and reference the `tags` system
property in your pom.

Aslak

BillR

unread,
Feb 3, 2012, 12:31:05 AM2/3/12
to Cukes


On Jan 30, 10:08 am, Aslak Hellesøy <aslak.helle...@gmail.com> wrote:
As indicated above, we are migrating from cuke4duke, which has been
the basis for ongoing happy test development.
A pair of us were befriended by a jBehave author at a selenium meetup,
and were lured by the promise of being an existing java solution,
moreover with easy parallelism.
One of the pair just translated a Scenario Outline using tables
(tables superimposed on tables, always fun to explain)and above-the-
numbers characters into the jBehave equivalent.
Nutshell: wire down the embedder to resemble cuke4duke, escape any $
signs in Examples, always get the parameterized rows when parsing a
table (to allow for intersection with Scenario Outline Examples), and
parallelism seems easy.
I haven't looked at it myself, aside from joining the email list,
which was harder to join, looks like they were spammed recently:
"Mailing Lists / Due to massive abuse by spammers the subscriptions is
centralized for email lists of all projects hosted on Codehaus. Users
need to register and manage email subscriptions."

Anyway, I was wondering if cuke-jvm has a multithreading model.
jBehave's is apparently just by the Feature file (I am sticking to
cuke nomenclature for now :-).

Bill

koteswara rao

unread,
Feb 3, 2014, 9:54:59 PM2/3/14
to cu...@googlegroups.com
Hi aslak , I am working on cucumber and now i have a question of how can i use to run specific tests run using Maven . can you please give some few tags where i can run at maven .

aslak hellesoy

unread,
Feb 4, 2014, 4:39:50 AM2/4/14
to Cucumber Users
On Tue, Feb 4, 2014 at 3:54 AM, koteswara rao <katt...@gmail.com> wrote:
Hi aslak , I am working on cucumber and now i have a question of how can i use to run specific tests run using Maven . can you please give some few tags where i can run at maven .


Hi Koteswara,

Please consider this for the future: http://cukes.info/posting-rules.html - especially the last rule.


Aslak

--
Posting rules: http://cukes.info/posting-rules.html
---
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.

Syed Arifulla

unread,
Sep 24, 2014, 8:15:28 AM9/24/14
to cu...@googlegroups.com


On Tuesday, February 4, 2014 9:39:50 AM UTC, Aslak Hellesøy wrote:



Hi Aslak
mvn clean test -Dtest.environment=panther.dev  -Dtest=RunAllTests -Dcucumber.arguments="--tags @usersonppc"
mvn clean test -Dtest.environment=panther.dev  -Dtest=RunAllTests -Dcucumber.options="--tags @usersonppc"

Both the above commands run all the tags inside RunAllTests .
 I want it to run only the tags @usersonppc
Can you tell me what is the correct command line to do that

 

Krishnakarthik G

unread,
Oct 5, 2015, 4:36:34 AM10/5/15
to Cukes
As u have mentioned,we can use 'tags' property to run particular scenarios.But,instead of getting the tag hard-coded,I want to pass it dynamically by using properties file or some variable.For that,I tried of passing variable to tag value but it is not accepting since @CucumberOptions is outside the class.Do you have any alternate solution for this.
Reply all
Reply to author
Forward
0 new messages