Skip to content

Commit f223012

Browse files
committed
add tests on cucumber
1 parent 089e917 commit f223012

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

pom.xml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,40 @@
9999
<groupId>io.micronaut.liquibase</groupId>
100100
<artifactId>micronaut-liquibase</artifactId>
101101
</dependency>
102+
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
103+
<dependency>
104+
<groupId>com.google.code.gson</groupId>
105+
<artifactId>gson</artifactId>
106+
<version>2.9.0</version>
107+
</dependency>
108+
109+
110+
111+
112+
<dependency>
113+
<groupId>junit</groupId>
114+
<artifactId>junit</artifactId>
115+
<version>4.12</version>
116+
</dependency>
102117

103118
<dependency>
104119
<groupId>io.micronaut.test</groupId>
105120
<artifactId>micronaut-test-rest-assured</artifactId>
106121
<version>3.4.0</version>
107122
<scope>test</scope>
108123
</dependency>
109-
110-
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
111124
<dependency>
112-
<groupId>com.google.code.gson</groupId>
113-
<artifactId>gson</artifactId>
114-
<version>2.9.0</version>
125+
<groupId>io.cucumber</groupId>
126+
<artifactId>cucumber-java</artifactId>
127+
<version>7.4.1</version>
115128
</dependency>
116129

130+
<dependency>
131+
<groupId>io.cucumber</groupId>
132+
<artifactId>cucumber-junit</artifactId>
133+
<version>7.4.1</version>
134+
<scope>test</scope>
135+
</dependency>
117136

118137
</dependencies>
119138

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.example.steps.api;
2+
3+
import io.cucumber.java.en.Then;
4+
import io.cucumber.java.en.When;
5+
import io.cucumber.junit.Cucumber;
6+
import io.cucumber.junit.CucumberOptions;
7+
8+
import io.restassured.response.Response;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.runner.RunWith;
11+
12+
import static io.restassured.RestAssured.given;
13+
14+
15+
@RunWith(Cucumber.class)
16+
@CucumberOptions(
17+
features = "src/test/resources/features/api",
18+
glue = "com.example.steps.api",
19+
plugin = { "pretty", "json:src/test/resources/features/api/cucumber.json"}
20+
)
21+
public class ApiRunnerTest {
22+
23+
int stcd;
24+
String rsbd;
25+
@When("I make request")
26+
public void i_make_request() {
27+
28+
Response response = given().port(8081).when().get("/greet/Ivan");
29+
int status_code = response.statusCode();
30+
String body = response.getBody().print();
31+
32+
stcd = status_code;
33+
rsbd = body;
34+
}
35+
36+
@Then("Response code is correct")
37+
public void response_code_is_correct() {
38+
Assertions.assertEquals(200, stcd);
39+
}
40+
@Then("Response body is correct")
41+
public void response_body_is_correct() {
42+
Assertions.assertEquals("Hi, nice to see you here Ivan", rsbd);
43+
}
44+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.example.steps.api;
2+
3+
public class Test {
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Test greeting controller
2+
3+
Scenario: Make request with existing name
4+
When I make request
5+
Then Response code is correct
6+
Then Response body is correct

0 commit comments

Comments
 (0)