Quarkus端点正常但测试报404错误,求排查方法
问题:QuarkusTest单元测试返回404,但实际请求正常
环境
- Quarkus版本:
quarkus.platform.version: 3.22.3
端点代码
import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; @Path("/ping") public class PingService { @GET @Produces(MediaType.TEXT_PLAIN) public String ping() { return "pong"; } }
应用配置
quarkus.http.root-path=api quarkus.http.non-application-root-path=/q
正常请求示例(可正常工作)
### Test ping GET http://localhost:8080/api/ping > {% client.test("Request executed successfully", function () { client.assert(response.status === 200, "Response status is not 200"); }); client.test("Response is plain text", function () { const type = response.contentType.mimeType; client.assert(type === "text/plain", `Expected 'text/plain' but received '${type}'`); }); client.test("Response to ping is pong", function () { const body = response.body; client.assert(body === "pong", `Expected 'pong' but received '${body}'`); }); %}
单元测试代码(返回404错误)
import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; @QuarkusTest class PingServiceTest { @Test void testHelloEndpoint() { given() .when().get("/ping") .then() .statusCode(200) .body(is("pong")); } }
错误信息
[ERROR] PingServiceTest.ping:15 1 expectation failed. Expected status code <200> but was <404>.
疑问
示例Quarkus应用无此问题,排查不出原因,想了解如何定位问题,比如能否在测试中显示REST映射?
内容的提问来源于stack exchange,提问作者chepseskaf
相关产品推荐
相关产品推荐

