[JVM] Option so that cucumber will NOT skip snippet steps

724 views
Skip to first unread message

ChrisWY

unread,
Nov 14, 2013, 4:59:18 PM11/14/13
to cu...@googlegroups.com
When Cucumber JVM goes through my feature file(s) and generates the java code snippets, it skips similar steps that is has already generated code for. For example if I have two separate features that both start with "@Given I view the login page" it will only generate the java code for the first occurrence. I know this is how most want to use cucumber but I want a 1 to 1 relationship for my implementation. Even if the step for both features is the same I want it to generate the java code twice. Yes I know this would create an issue if I put all my Java into a single file but I am not.

Is there an option I can use or a way to force cucumber to generate a snippet for each feature step?

Thank you in advance :)

aslak hellesoy

unread,
Nov 14, 2013, 5:15:49 PM11/14/13
to Cucumber Users
On Thu, Nov 14, 2013 at 9:59 PM, ChrisWY <cyaskos...@gmail.com> wrote:
When Cucumber JVM goes through my feature file(s) and generates the java code snippets, it skips similar steps that is has already generated code for. For example if I have two separate features that both start with "@Given I view the login page" it will only generate the java code for the first occurrence. I know this is how most want to use cucumber but I want a 1 to 1 relationship for my implementation. Even if the step for both features is the same I want it to generate the java code twice. Yes I know this would create an issue if I put all my Java into a single file but I am not.


Step definitions are global. They are not scoped to any particular features or scenarios. If you create two step definitions with identical patterns you will get a runtime error (duplicate stepdef). This will happen regardless of whether you define them in the same java class or different ones.

This is why you won't see stepdefs printed more than once. We wouldn't want to encourage you to do something that won't work.

Aslak

Is there an option I can use or a way to force cucumber to generate a snippet for each feature step?

Thank you in advance :)

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

cyas...@gmail.com

unread,
Nov 15, 2013, 10:40:59 AM11/15/13
to cu...@googlegroups.com
Thank you for the reply. I was going to write my own run manager that would individually pick and run the java files. Would doing it this way still cause a conflict? If not, going back to my original question, despite being frowned upon, can you force Cucumber to output 1:1 relationship snippets and ignore the fact that its a duplicate?
Thank you,

aslak hellesoy

unread,
Nov 15, 2013, 11:39:36 AM11/15/13
to Cucumber Users
Please don't top post. See rule 2 in the email footer.


On Fri, Nov 15, 2013 at 3:40 PM, <cyas...@gmail.com> wrote:
Thank you for the reply. I was going to write my own run manager that would individually pick and run the java files. Would doing it this way still cause a conflict?

All step definitions are stored inside RuntimeGlue. Adding one with the same pattern as one that is already added will throw a DuplicateStepDefinitionException.

If you implement your own glue that doesn't do this, you would end up with an ambiguous lookup. You have two stepdefs that match a step. Which one do you pick?
 
If not, going back to my original question, despite being frowned upon, can you force Cucumber to output 1:1 relationship snippets and ignore the fact that its a duplicate?

Why would we do that if it's going to lead you into the situation where you'll end up with duplicate stepdefs?

Aslak

aslak hellesoy

unread,
Nov 15, 2013, 12:58:19 PM11/15/13
to Cucumber Users
Please do not email me privately. Here is why:

I'm bringing this discussion back to the list.

On Fri, Nov 15, 2013 at 5:32 PM, <cyas...@gmail.com> wrote:


On Friday, November 15, 2013 11:39:36 AM UTC-5, Aslak Hellesøy wrote:
Please don't top post. See rule 2 in the email footer.


On Fri, Nov 15, 2013 at 3:40 PM, <cyas...@gmail.com> wrote:
Thank you for the reply. I was going to write my own run manager that would individually pick and run the java files. Would doing it this way still cause a conflict?

All step definitions are stored inside RuntimeGlue. Adding one with the same pattern as one that is already added will throw a DuplicateStepDefinitionException.

The framework we came up with was to use cucumber to auto generate the java snippets and create individual java files for each feature. From there we would use our own run manager with selenium integrated to kick off the java file, read through it, and then determine if it passed or failed. My understanding is that the run manager would not be looking at any feature files at this point and would just run the java code that we have supplied for the single feature and execute it that way. It should not have to make a decision as to which step to pick because the steps with all supplied code would be in the individual java files and it would only be looking in that one java file. Perhaps we are not using Cucumber correctly so please let me know if there are obvious flaws in my thinking.

It sounds like you are using Cucumber-JVM very differently from how it's intended to be used. It sounds like you are complicating things by building stuff around it.

You're not supposed to create something outside cucumber to start cucumber.
Instead, start cucumber from your preferred build tool:

* Maven
* Ant
* IDE
* Script

And use one of the following built-in runners:

* JUnit
* cucumber.cli.api.Main
* Android runner

If you want to run a subset of features, do so with --tags.

Aslak



My only other comment would be that if doing it the other way where cucumber generates the java code for say 150 features,

I don't understand what you mean. Cucumber doesn't generate code at all.

It just prints a stepdef snippet to stdout when it encounters a gherkin step it can't match. Typically this would be 2-3 steps when you're working on a new scenario.

If you have hundreds of undefined steps you should definitely consider a more incremental development process.

Aslak
 
and all that java code sits inside one java file, maintaining that file would be difficult. If the "log-in" button where changed to say "sign-in" and you only wanted to change the one code line to correct this, it would be difficult to look through the entire java file to find this one line. Doing it the other way you could say, "oh Feature 29 tests log-in" and just update the code under "@Given" in Feature 29's Java file.

cyas...@gmail.com

unread,
Nov 15, 2013, 1:36:55 PM11/15/13
to cu...@googlegroups.com


On Friday, November 15, 2013 12:58:19 PM UTC-5, Aslak Hellesøy wrote:
Please do not email me privately. Here is why:

I apologize I did not realize that I did. First time ever using google groups and I hit the wrong button.
 
I'm bringing this discussion back to the list.

On Fri, Nov 15, 2013 at 5:32 PM, <cyas...@gmail.com> wrote:


On Friday, November 15, 2013 11:39:36 AM UTC-5, Aslak Hellesøy wrote:
Please don't top post. See rule 2 in the email footer.


On Fri, Nov 15, 2013 at 3:40 PM, <cyas...@gmail.com> wrote:
Thank you for the reply. I was going to write my own run manager that would individually pick and run the java files. Would doing it this way still cause a conflict?

All step definitions are stored inside RuntimeGlue. Adding one with the same pattern as one that is already added will throw a DuplicateStepDefinitionException.

The framework we came up with was to use cucumber to auto generate the java snippets and create individual java files for each feature. From there we would use our own run manager with selenium integrated to kick off the java file, read through it, and then determine if it passed or failed. My understanding is that the run manager would not be looking at any feature files at this point and would just run the java code that we have supplied for the single feature and execute it that way. It should not have to make a decision as to which step to pick because the steps with all supplied code would be in the individual java files and it would only be looking in that one java file. Perhaps we are not using Cucumber correctly so please let me know if there are obvious flaws in my thinking.

It sounds like you are using Cucumber-JVM very differently from how it's intended to be used. It sounds like you are complicating things by building stuff around it.

You're not supposed to create something outside cucumber to start cucumber.
Instead, start cucumber from your preferred build tool:

* Maven
* Ant
* IDE
* Script

And use one of the following built-in runners:

* JUnit
* cucumber.cli.api.Main
* Android runner

If you want to run a subset of features, do so with --tags.

Aslak

In our old world we define test cases and have the ability to execute individual cases. We were trying to use a run manager to run the one java file for the single feature which would kind of act as a test case. We have each case or "feature" name listed in an excel file that we can use to select which ones to run and then feed that list into the run manager to execute the cases we selected to run.



My only other comment would be that if doing it the other way where cucumber generates the java code for say 150 features,

I don't understand what you mean. Cucumber doesn't generate code at all.

When I say generate code I mean the java snippets it generates for the feature steps.
 
It just prints a stepdef snippet to stdout when it encounters a gherkin step it can't match. Typically this would be 2-3 steps when you're working on a new scenario.

If you have hundreds of undefined steps you should definitely consider a more incremental development process.

We are only going to be automating 20 or so features per sprint however over the course of the project we will end up with 150+. At the end of the project the features will be moved to run as regression and my thoughts were that if we only wanted to change one small thing for a given feature (like my log-in / sign-in example), it would be a pain to look through the one very large java file that contains our automation code to find that line.

Do people typically just use one large java file that contains all the java snippets for the features they want to test?

Aslak Hellesøy

unread,
Nov 15, 2013, 1:59:39 PM11/15/13
to cu...@googlegroups.com
Just to avoid confusion, the correct term is Step Definitions. (Cucumber prints Step Definition snippets).
for the features they want to test?
 
No, the recommended approach is to have a class per domain concept: 


You can use one of cucumber-jvm's many DI libraries to wire them together.

Aslak

cyas...@gmail.com

unread,
Nov 15, 2013, 4:20:27 PM11/15/13
to cu...@googlegroups.com
Thank you for your patience with me. As you can tell I am VERY new to cucumber. Before I even saw your reply I was talking to my team and said that we will probably have to break our class files down to domains instead of our initial 1:1 idea. Your reply is all the confirmation I need that this is the right choice. Thanks for pointing me in the right direction, we've already started working on this.

Roberto Lo Giacco

unread,
Nov 16, 2013, 7:04:24 AM11/16/13
to cu...@googlegroups.com
Il giorno venerdì 15 novembre 2013 22:20:27 UTC+1, cyas...@gmail.com ha scritto:
Thank you for your patience with me. As you can tell I am VERY new to cucumber. Before I even saw your reply I was talking to my team and said that we will probably have to break our class files down to domains instead of our initial 1:1 idea. Your reply is all the confirmation I need that this is the right choice. Thanks for pointing me in the right direction, we've already started working on this.

May I suggest you to understand the Cucumber approach before starting such task? I believe you don't want to spend all your time refactoring over and over your files and the fact you were planning to create your own runner and you didn't understand the step definition concept leads me to think you need to spend some time learning before you can actually produce a valid solution.

I would advice to experiment and read a little bit on a small scale before trying to provide a system wide solution.

Just as an example: if you are using Cucumber to create an automated test suite then you are missing a big value point of Cucumber.

cyas...@gmail.com

unread,
Mar 19, 2014, 11:56:23 AM3/19/14
to cu...@googlegroups.com
I know this is an old post but please elaborate why Cucumber would not work for an automated test suite? 

aslak hellesoy

unread,
Mar 19, 2014, 12:21:33 PM3/19/14
to Cucumber Users
Are you using Cucumber as a collaboration tool as well?
If not you might just as well use JUnit.


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/d/optout.

Roberto Lo Giacco

unread,
Mar 19, 2014, 2:17:06 PM3/19/14
to cu...@googlegroups.com
Il mercoledì 19 marzo 2014, <cyas...@gmail.com> ha scritto:

Just as an example: if you are using Cucumber to create an automated test suite then you are missing a big value point of Cucumber.

I know this is an old post but please elaborate why Cucumber would not work for an automated test suite? 

Aslak already replied on this, but I believe I'll spend a few words on this to make my thinking clearer.

Cucumber has a value which resides in the expressiveness of an almost natural language. As a test language it doesn't provide anything because when it comes down to testing each and every step is just matched against a method and that code gets executed.
The testing part is still expressed in your code, be it Java or some other JVM language.

If you write your feature files with the only purpose of building an automation test suite then you'll end up with features looking like pseudo code: the benefit of such feature files is arguable and the additional effort required to write and maintain represents a waste of time. You can achieve the exact same goal with decently organized classic test classes (JUnit, TestNG, etc...).

The benefit of using cucumber is when you write your feature files by using the same language your business partners use, allowing the dev and test team to fill the gap with the business, improve the communication and reduce the misunderstandings. This means the feature files are written TOGETHER with the business or at least the business provides feedback on them.

If you get to that point then your feature files will describe the system from a business point of view acting as specifications for the development and documentation for anybody doing maintenance or evolution.

The automation you might get is just a nice side effect of the documentation process. Do it the other way around and you'll find yourself wasting time going back and forth on files only you understand and nobody else read.

To put it very simple: if you write the feature files alone and nobody outside of the developers/testers circle reads them then think twice about the value you are getting back.

To close up: I'm not suggesting to stop using Cucumber, I'm suggesting to share it with your business partners. 

I strongly believe Cucumber is a good tool for BDD, but I see it too many times confused as an automation testing tool....
Reply all
Reply to author
Forward
0 new messages