My question is about a geb-spock Spec but I think my question applies
to Spock in general.
My GebSpec tests end-to-end behaviour on a system that is more complex
than anyone likes :)
I have a very long system test with about 20 when/then pairs, and it
is parameterized.
I would like modularize make elements of this long test. My first
instinct was to put those blocks in private methods, but that doesn't
work, because I can't use the when: and then: labels inside those
private methods.
Do you guys have a recommended approach?
Cheers,
Hans
> --
> You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
> To post to this group, send email to spockfr...@googlegroups.com.
> To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
>
>
Cheers,
Hans
Time for me to revisit this issue...
As I posted before, I have very long GebReportingSpec features, but
the question I have relates to Spock's core features, that's why I
think this is the appropriate list. Let me describe the situation. I
was asked to implement a bunch of end-to-end functional tests that
each cover at least 8 pages and will visit some of those multiple
times. You can imagine that, if I apply no means of modularizing some
of the steps, I will end up with endless sequences of when/then and a
lot of duplicated lines.
My first instinct was to put some of these steps into closures, which
I could then re-use across multiple feature-specs, the advantage being
that the 'current geb page' would remain intact and I could refer to
it.
But I found out that Spock would not do anything with any of the when/
then blocks, most notably with the 'then' blocks, whose assertions
were not seen as assertions anymore. For now, I am using classic JUnit
assertTrue statements inside those closures. But that is not the nice
Spock stuff I am after :)
So, FYI, my test look like this
class SomeSpec extends GebReportingSpec(){
def 'my feature spec'(){
given:
// some situation
buildingBlock()
// dosomething else that sets this test apart
anotherBuildingBlock
}
// a bunch more feature specs that also reuse the blocks below
def buildingBlock = {
// do geb stuff that gets reused
// do JUNIT style asserts
Assert.assertTrue (whatever)
}
def anotherBuildingBlock1 = {
// do other geb stuff that also reused
}
}
So, I am looking for a way to modularize my tests that allows:
-1. keeping those long 8 page scenarios. (these are just required by
the nature of the system under test)
-2. code-reuse for some of the basic steps in those scenarios
-3. Continue to use when/then inside the aforementioned closures
Does anyone have a recipe for this?
Cheers,
Hans
Does Hans, or anyone, have tips on how to do this?I'm trying to do what Hans was, also using Geb+Spock, and I don't see a clean way of separating sets of repeated Geb testSteps so that I can reuse them across various features(methods).Note that @Stepwise isn't sufficient because it doesn't allow reuse across multiple features.
Also, it introduces feature(test) interdependence, which is generally undesirable.