> Hi,
> I am planning to use cucumber-java for my java project for automated
> testing. I would like to know if there is any option in cucumber, by
> which we can explicitly provide dependency among running scenarios. For
> example:
>
There is not, and there probably never will be. With any testing framework -
if the outcome of a test A depends on whether or not test B has run before
it - then you have created for yourself (and your team) a formidable time
waster.
Everyone will spend lots of time figuring out why a test is failing under
some circumstances and not under others. Every week there is a new person on
this list asking something like:
"Why do all my (Cucumber/RSpec) tests pass when I run them all with Rake,
but not when I run one individually?"
The answer is always the same:
"Because they are coupled"
Then they go debugging for an hour, sometimes several days and come back
with:
"I finally found out where the coupling is. How can I decouple them?"
If I make it easier for people to run scenarios in a certain order, I also
make give people more rope to hang themselves with. People will inevitably
end up in the situation I just described. And then everybody's time gets
wasted.
Actually - in Cucumber - the objects created in one scenario will never be
available to the next scenario. Of course you can work around this (shoot
yourself in the foot) by storing state in static/class variables or in a
database, but I don't recommend it.
> I have a ValidateProfile.java and a ProfileSignIn.java.
>
> public class ValidateProfile {
> ...
> public ValidatedProfile validate(String userName, String password) {
> ...
> ...
> }
> }
> public class ProfileSignIn {
> public void doSignIn(ValidatedProfile profile) {
> ...
> ...
> }
> }
>
> Suppose I have a step definition for ValidateProfile as:
> public class ValidateProfileTest {
> @Given("I have user credential as (.*) and (.*)$")
> public void setCredentials(String userName, String password) {
> // set credentials to members
> ...
> }
> @When("I call Validate Profile")
> public void validateProfile() {
> ...
> ValidatedProfile profile = validateProfile.validate(_userName,
> _password);
> // set profile in class member
> ...
> }
> @Then("Profile should validate successfully() {
> // assert contents of Validated Profile
> }
> }
>
> Now I would like to create a Test case, say ProfileSignInTest, for
> ProfileSignIn. As ProfileSignIn requires a ValidatedProfile, I would
> like to run ValidateProfileTest prior to that and make use of the
> ValidatedProfile as input to ProfileSignInTest.
>
> Before running a scenario in ProfileSignInTest's feature(say
> profilesignin.feature) , Is there any option to run the features of
> ValidateProfileTest(say validateprofile.feature), get its output and
> pass the same as input to profilesignin.feature 's scenario as below:
>
> validateprofile.feature
> -----------------------
> @getValidatedProfiles
> Given I have a username and password
> When I call Validate Profile
> Then Profile should validate successfully
>
> profilesignin.feature
> ---------------------
> @profilesignin
> use output as validatedProfile from @getValidatedProfiles
> Given I have the validated profile as validatedProfile
> When I call SignIn
> Then I should get Signed In successfully
>
> My idea is to make use of hooks as below, and if possible pass the
> output of @getValidatedProfiles to the 'Given' of @profilesSignin. If
> that's not possible, I can make use of a java framework to store and
> retrieve the output, but the priority is to make a scenario dependent on
> one or more other scenarios.
>
> Before('@profilesignin') do
> //run the scenario with tag @getValidatedProfiles
> end
>
> Other than hooks, If there are any other better ways of handling
> this, please let me know.
>
I think I understand what you're after.
Hooks are not yet implemented in cucumber_java (but it would be fairly easy
to implement). If you think this
is what you need - please create a ticket in cucumber_java's github tracker.
But maybe Background is a better fit in this case?
http://wiki.github.com/aslakhellesoy/cucumber/background
It should work fine with cucumber_java.
Cheers,
Aslak
>
> Thanks,
> Neema
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users