I have many working / passing geb / spock functional tests (each of which extends to GebReportingSpec) that test a web application with test data, all created from BootStrap.groovy, at the beginning of the functional test suite.
I want to move the creation of test data to the startup () / teardown () methods inside each Spec, well, actually, I wanted them to inherit it from the base class, but obviously, StepWise has problems with inheritance.
So, currently, each of my test class classes looks something like this:
@Stepwise class ExampleSpec extends GebReportingSpec { def "valid root user logs in"() { given: "I am at the login page" to LoginPage when: "I enter root credentials" username = "root" password = "password" and: "I click the login button" loginButton.click() then: "I am logged in and directed to the welcome page" at WelcomePage } }
Now my problem is that I cannot create a new test (above the first test) that can create test data. Without a valid given / if / then test, the test seems to fail, and calling the method from the existing test also fails. I looked into the grails-remote-control plugin to help me, and I believe that this will allow me to successfully declare a close for data installation, but I'm not sure of the best mechanism to call this from GebReportSpecs (or some abstract parent).
Below is a brief overview of what I want to do, either by making "setupData ()" the first test, or by calling this method from the test ... Nothing works.
def remote = new RemoteControl() def setupData() { def id = remote { def ShiroUser user = new ShiroUser(username: "root", ...) user.save() user.id } println(id) } .... Tests then follow
Are there any annotations like @before etc. that can cause these methods to be called?
Any suggestions are welcome.
Solution: I accepted the dmahapatro answer below with the correct answer, but also provided an example of my final solution below for those who may find this useful.