Forum: RSpec Cucumber: Setting Dependency among scenarios

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
78830e872b7daf041384425696803581?d=identicon&s=25 Neema Cheriyath (goodneema)
on 2009-04-27 06:44
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:

    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.

Thanks,
Neema
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-27 08:56
(Received via mailing list)
> 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.


>      public void doSignIn(ValidatedProfile profile) {
>    ...
>    // 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.
>

>    Then Profile should validate successfully
> output of @getValidatedProfiles to the 'Given' of @profilesSignin. If
>
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
78830e872b7daf041384425696803581?d=identicon&s=25 Neema Cheriyath (goodneema)
on 2009-04-29 11:10
Thank you Aslak.

Let me see whether I can make use of Background for implementing the
dependency issue that I mentioned.

I think implementing hooks in cucumber_java will be useful for us, since
we can make use of that to get a detailed report with all the required
information while running the scenarios in cucumber.

I will create a ticket to implement hooks in cucumber_java.

Thanks,
Neema
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-29 11:14
(Received via mailing list)
On Wed, Apr 29, 2009 at 11:10 AM, Neema Cheriyath
<lists@ruby-forum.com>wrote:

>
Thanks Neema. Please use the GitHub tracker in the cucumber_java
projects. I
want to keep issues separate from Cucumber core (Lighthouse)

Aslak
78830e872b7daf041384425696803581?d=identicon&s=25 Neema Cheriyath (goodneema)
on 2009-04-29 11:34
Hi Aslak,
           I have created a new ticket in github for implementing hooks
in cucumber_java. Please find the link:

http://github.com/aslakhellesoy/cucumber_java/issu...

Thanks,
Neema
This topic is locked and can not be replied to.