如何在Swagger的测试中验证API? [英] How to validate API in tests with Swagger?

查看:726
本文介绍了如何在Swagger的测试中验证API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出使我的API文档成为真相的最佳方法,并理想地通过集成测试或类似的方式使用它来验证实际的Java REST代码.我们使用的是合同优先"或消费者合同"类型的方法,因此我们不希望文档必须从带注释的代码中生成,并且每次开发人员进行更改时都进行更新.

I'm trying to figure out the best way to have my API documentation be the source of truth and use it to validate the actual Java REST code ideally through integration testing or something of that sort. We're using the contract first or consumer contract type of approach, so we don't want the documentation to be generated from annotated code necessarily and updating every time a developer makes a change.

一个想法是使用Swagger,但是我不确定如何最好地使用它来验证API.理想情况下,最好在构建或集成测试过程中进行验证,以查看实际响应(如果可能,并进行请求)是否符合预期.我知道Swagger有很多用途和工具,只是想把它包裹住.或者,如果有更好的替代方法可以使用Java代码.

One thought has been to use Swagger, but I'm not sure how best to make it be used for validating the API. Ideally, it'd be good to have the validation occur in the build or integration testing process to see if the real response (and request if possible) match what's expected. I know there are a lot of uses and tools for Swagger and just trying to wrap my head around it. Or if there is a better alternative to work with Java code.

推荐答案

最近,我们(swagger-codegen社区)开始向API客户端(C#,PHP,Ruby)添加自动生成测试用例.我们尚未将其添加到Java中.这是Swagger-Codegen为C#生成的一些示例测试用例:

Recently, we (swagger-codegen community) start adding automatic test case generation to API clients (C#, PHP, Ruby). We've not added that to Java yet. Here are some example test cases generated by Swagger-Codegen for C#:

这仍然是非常初步的,我们希望听到您的反馈,以了解您是否正在寻找它.

It's still very preliminary and we would like to hear feedback from you to see if that's what you're looking for.

这篇关于如何在Swagger的测试中验证API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆