Skip to content

Commit

Permalink
Merge pull request #147 from tbounsiar/issue/79_-_Add_@BeforeAll_and_…
Browse files Browse the repository at this point in the history
…@AfterAll_support

add support of beforeall and afterall hooks
  • Loading branch information
christophd authored Mar 20, 2024
2 parents ee28652 + 6c31946 commit 0bec0cb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class Endpoint {

@GET
public String hello() {
return "hello";
return Factory.hello();
}
}
14 changes: 14 additions & 0 deletions deployment/src/test/java/io/quarkiverse/cucumber/test/Factory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkiverse.cucumber.test;

public class Factory {

private static boolean justeHello = false;

public static void setJusteHello(boolean justeHello) {
Factory.justeHello = justeHello;
}

public static String hello() {
return justeHello ? "hello" : "hello from factory";
}
}
24 changes: 24 additions & 0 deletions deployment/src/test/java/io/quarkiverse/cucumber/test/Steps.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.quarkiverse.cucumber.test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertFalse;

import jakarta.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import io.cucumber.java.AfterAll;
import io.cucumber.java.BeforeAll;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.restassured.response.ValidatableResponse;
Expand All @@ -18,6 +22,21 @@ public class Steps {

private ValidatableResponse result;

@BeforeAll
public static void beforeAll() {
Factory.setJusteHello(true);
}

@AfterAll
public static void afterAll() {
Factory.setJusteHello(false);
String response = given()
.when().get("/")
.then()
.extract().body().asString();
assertFalse("hello".equals(response));
}

@Given("I call the endpoint")
public void i_call_endpoint() throws Exception {
result = given()
Expand All @@ -30,4 +49,9 @@ public void response_is_ok() throws Exception {
result.statusCode(200);
}

@Then("the response body is hello")
public void response_body_is_hello() throws Exception {
result.body(is("hello"));
}

}
3 changes: 2 additions & 1 deletion deployment/src/test/resources/simple.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Feature: Test feature

Scenario: Test scenario
Given I call the endpoint
Then the response is ok
Then the response is ok
And the response body is hello
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ List<DynamicNode> getTests() {

List<DynamicNode> features = new LinkedList<>();
features.add(DynamicTest.dynamicTest("Start Cucumber", context::startTestRun));
features.add(DynamicTest.dynamicTest("Before All Features", context::runBeforeAllHooks));

Predicate<Pickle> filters = new Filters(runtimeOptions);

Expand Down Expand Up @@ -155,6 +156,7 @@ List<DynamicNode> getTests() {
}
});

features.add(DynamicTest.dynamicTest("After All Features", context::runAfterAllHooks));
features.add(DynamicTest.dynamicTest("Finish Cucumber", context::finishTestRun));

return features;
Expand Down

0 comments on commit 0bec0cb

Please sign in to comment.