繁体   English   中英

如何通过Spring依赖注入为Jersey Rest编写JUnit测试用例

[英]How to write junit test cases for Jersey rest with spring dependency injection

我有使用像spring,hibernate和Jersey Jax-rs rest之类的技术的Web应用程序来进行Web服务。 我可以为Dao层以及Service层编写junit测试用例,但是我无法为jersey Rest编写内部注入弹簧组件的junit测试用例。 有人可以帮忙吗? 谢谢。

您可以使用RestAssured进行休息单元测试

你可以在那找到详细的解释

http://rest-assured.io

我自己的试用样品休息单元测试

@Test
public void createEntityShouldReturnCreated() throws Exception {
    given().port(DemoApplicationTests.serverPort).contentType("application/json").body(detailDto).when()
            .post("/api/employee").then().statusCode(201)
            .header("X-demoApp-alert", "demoApp.entity.created");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM