I am writing a Grails-5 and I am using cucumber for BDD. I've followed the tutorial at: https://www.baeldung.com/java-cucumber-gradle
I can run my unit tests using:
$ ./gradlew check
And I can run my cucumber BDD tests by starting the server in one shell:
$ ./gradlew server:bootRun
And invoking the tests in another:
$ ./gradlew cucumberCli
Is it possible to configure build.gradle
in such a way as to have ./gradlew check
run the unit tests, then start the server, then run the cucumber tests, and finally bring the server back down?
If at all possible, it would be even better if the cucumber infrastructure could start and stop the server between each test. That way each test would start in a known state.
I managed to get this working by adding @Before
and @After
steps to my StepDefinitions.groovy
file:
def serverProcess
private String getBaseUrl() {
return "http://localhost/"
}
@Before
public void startServer() {
try {
serverProcess=Runtime.getRuntime().exec("../gradlew bootRun")
} catch (IOException e) {
e.printStackTrace()
}
def done = false
while(!done) {
try {
done = new URL(getBaseUrl()).openConnection().getResponseCode() == 200
} catch(Exception e) {
Thread.sleep(500)
}
}
}
@After
public void stopServer() {
serverProcess.destroy()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.