The Problem
Take a look at the below two feature files (click for high-res viewing):Feature File |
Conceptually global step functions look like this (click pic for high resolution image):
Global Scope Step Definitions in a global 'dictionary' |
But perhaps, you want this for fine grain control and let the developer control all aspects of how each step in the feature file is automated (click pic for high resolution image):
Each feature file has it's own namespace for steps definitions |
You can get to this extreme with some easy to do but additional steps.
Global Scope
This one is easiest to get started with as Cucumber is geared to make this easy. Your test automation project should have package arranged like:test.pageobjects
test.features
test.features.major_feature_one
test.features.major_feature_one.subfeature
test.features.major_feature_two
...
Create a JUnit execution class at the top of your test automation project like shown.
How everything works is that when launching the JUnit test case, it hands off to Cucumber via the @RunWith, which associates all the subpackage from that point as the namespace to use for matching step definitions. So by putting the JUnit Test class at test.features makes all of our feature files from test.features and downward, match to any of the step definitions declared from this point on down. (BTW, there are tools such as Natural that help in editing feature files and finding which step definition is active.)
Here's the big news: Nothing is stopping us from having multiple JUnit Test classes in different peer packages, effectively creating boundaries for how step functions are picked up by feature files.
Package Scope
By putting a Cucumberized JUnit Test case at the top of specific packages, we create separate bounded contexts, a term used by the practice Domain Driven Design, which basically sums up to: put the features and steps for the package delivery in one Java namespace and the features and steps for multiuser in another Java namespace, and then in each package, setup a Cucumberized JUnit Test case. In this way, boundaries between these two different domains are made.
It looks like this:
Package organization |
test.features.packagedeliver contains one Cucumberized JUnit Test case, many steps definitions, and many feature files. test.features.processcontrol contains one Cucumberized JUnit Test case, many steps definitions, and many feature files.
Thusly its possible to have a "Then signoff" defined in a steps definition in the processcontrol context and a different definition for "Then signoff" by a steps definition in the packagedelivery context. If another "Then signoff" steps definition is added to say, test.features.processcontrol.increase_system_load, Cucumber will put the brakes on and complain that "Then signoff" is ambiguous as there are multiple definitions in its bounded context.
But what if that isn't enough? Can we make every feature file have its own context? You bet.
Feature File Scope
If you need to do this, it's a bit of drudge work but it's not complex: for every feature file you'll need to add a Cucumberized JUnit test case, and due to a lovely quirk of Cucumber, drop that feature file's step definitions in their own package. #annoying
Conceptually that looks like this:
Literally, it looks like this (click image to see what's going on):
Two feature files in the test.features.processcontrol package want different step definitions for "Then signoff"
Now each Cucumberized JUnit test case defines the mapping from a specific feature file and a package to where to load its step definitions. Because this strategy will end up producing a bunch of different JUnit test cases, you'll want to add a JUnit test suite so you can easily execute all your feature tests with one click.
Conclusions
You've got the tools to do whatever you want with Cucumber. Treating every feature file as having its own scope is the ultimate of control but do you really need that? The OCD control freak inside does want that and if so, better to find another framework to support that then Cucumber. Defining boundaries using packages will keep the DDD people happy and would work in a pinch when you need it. Cucumber is courageous in pushing people to build global dictionaries. I've only heard of great drama coming out of such striving though people have successfully done it. It seems unfair to having our language in feature files be global context (easy to do as we are humans) and then forcing the automation (a computer program) to discover the context when Gherkin doesn't pass along all the context from the feature files.
I'm happy to hear from you if you've a story to share: Twitter:@LancerKind, LancerKind@gmail.com.
I'm happy to hear from you if you've a story to share: Twitter:@LancerKind, LancerKind@gmail.com.
References
- Learn style tips for writing your Gherkin with Behavior Driven Development Elements of Style.
- CucumberOptions
- CucumberOptions Javadoc
- JUnit 4 Test Suites
Images are not working anymore, can you please fix them.
ReplyDeleteConfessions Of An Agile Coach: Teaching Cucumber About Boundaries >>>>> Download Now
Delete>>>>> Download Full
Confessions Of An Agile Coach: Teaching Cucumber About Boundaries >>>>> Download LINK
>>>>> Download Now
Confessions Of An Agile Coach: Teaching Cucumber About Boundaries >>>>> Download Full
>>>>> Download LINK Ho
Confessions Of An Agile Coach: Teaching Cucumber About Boundaries >>>>> Download Now
ReplyDelete>>>>> Download Full
Confessions Of An Agile Coach: Teaching Cucumber About Boundaries >>>>> Download LINK
>>>>> Download Now
Confessions Of An Agile Coach: Teaching Cucumber About Boundaries >>>>> Download Full
>>>>> Download LINK
Thanks and that i have a swell proposal: What Was The First Home Renovation Show home addition contractor
ReplyDelete