cucumber-jvm equivalent of jbehave @BeforeStory and @AfterStory

269 views
Skip to first unread message

Paul Harris

unread,
Mar 1, 2012, 7:42:32 AM3/1/12
to Cukes
Hi,

I was wondering if there was a way to perform the equivalent of
@BeforeStory and @AfterStory (from Jbehave) in cucumber-jvm. What I
would basically like is a way to have something run once before a
feature file and once when it is done. I tried to look into the the
hooks but they seem to work on a per scenario basis only.

I would also be interested in knowing if there is also a hook above
this e.g. it will run once regardless of the number of feature files
before anything is done and once after everything is complete.

I might be being stupid and have just missed how to accomplish this,
with ruby it is was obviously done outside of cucumber in the ruby
files itself so it might be that I have to do the same here.

Thanks for help,

Paul

Aslak Hellesøy

unread,
Mar 1, 2012, 7:51:36 AM3/1/12
to cu...@googlegroups.com


On Thursday, March 1, 2012 12:42:32 PM UTC, Paul Harris wrote:
Hi,

I was wondering if there was a way to perform the equivalent of
@BeforeStory and @AfterStory (from Jbehave) in cucumber-jvm. What I
would basically like is a way to have something run once before a
feature file and once when it is done. I tried to look into the the
hooks but they seem to work on a per scenario basis only.


No, currently not.

What is it that you want to run once per feature, and why only once?
 
I would also be interested in knowing if there is also a hook above
this e.g. it will run once regardless of the number of feature files
before anything is done and once after everything is complete.


Regular static java code blocks. And regular java shutdown hooks.

Aslak

Paul Harris

unread,
Mar 1, 2012, 10:07:48 AM3/1/12
to Cukes
I am currently putting together a framework to be able to use cucumber
with robotium and as part of running any scenario i have a dependancy
that i have a connection to the phone which requires instrumentation
to be running. Starting up the connection and instrumentation
currently takes ~15 seconds, that is an amount of time that adds up
when you have a large test suite so i was hoping to be able to
potentially reuse the connection among scenarios when possible. The
simplest enhancement would have come from just being able to use an
equivalent of @BeforeStory but sounds like i might have to do it in
the 'hard' way.

Thank for confirming what I thought.

aslak hellesoy

unread,
Mar 1, 2012, 10:12:25 AM3/1/12
to cu...@googlegroups.com
On Thu, Mar 1, 2012 at 3:07 PM, Paul Harris <paulb...@gmail.com> wrote:
> I am currently putting together a framework to be able to use cucumber
> with robotium and as part of running any scenario i have a dependancy
> that i have a connection to the phone which requires instrumentation
> to be running. Starting up the connection and instrumentation
> currently takes ~15 seconds, that is an amount of time that adds up
> when you have a large test suite so i was hoping to be able to
> potentially reuse the connection among scenarios when possible.

Is there any particular reason you can't do this once for the entire
run in a static block?
Why do you need it per-feature?

Aslak

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

Paul Harris

unread,
Mar 1, 2012, 10:20:49 AM3/1/12
to Cukes
It is quite a specific case but basically with an android
instrumentation test you need to start up a certain android activity
which is defined at compile time. Features tend to use the same entry
point to the application (or could with planning) and so this screamed
to me as a simple way to allow you to pick different entry points into
the application. I can work around it, just was hoping for a quick way
to try it out without hacking too much at the (currently) messy code
base I have put together to determine if the whole project is going to
be useful.

Paul

On Mar 1, 3:12 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:

Andrew Premdas

unread,
Mar 1, 2012, 2:19:55 PM3/1/12
to cu...@googlegroups.com
You could  use static blocks to setup some global tools for your instrumentation. Then call these tools via tags for each scenario. Finally use memorisation and conditionals in the global tools to get the required initialisation, frequency.

Hope that makes sense

Andrew
--
------------------------
Andrew Premdas

Aslak Hellesøy

unread,
Mar 1, 2012, 4:55:45 PM3/1/12
to cu...@googlegroups.com




On Mar 1, 2012, at 19:19, Andrew Premdas <apre...@gmail.com> wrote:

You could  use static blocks to setup some global tools for your instrumentation. Then call these tools via tags for each scenario. Finally use memorisation and conditionals in the global tools to get the required initialisation, frequency.

Hope that makes sense


I had the exact same idea. File a ticket if you want a code example. I think it would be useful to document anyway.

Aslak
Reply all
Reply to author
Forward
0 new messages