首页 > web前端 > js教程 > 正文

API 测试变得轻松:KushoAI

Barbara Streisand
发布: 2024-10-14 14:26:29
原创
510 人浏览过

有没有想过为什么我们使用研磨机,而我们的祖先却徒手进行所有研磨?增强的技术帮助我们超越了上一代,实现了日常工作的自动化,这使我们能够更多地关注生活的其他方面,从而带来更多的发现。与当今的工程师坐下来几个小时试图处理 API 调用中传递的所有信息不同,您希望提高工作效率并更多地关注处理数据以将一些有用的代码融入现实生活中公用设施。

作为一名后端工程师,我理解没有完全掌握 API 端点服务器如何运作的困难 - 或者更准确地说,没有完全理解(?)我们的 API 端点服务器如何运作的挫败感。此外,了解 API 端点的最佳性能和测试运行时环境一致成为工程师的首要任务。因此,我们测试 API 的方式最终决定了我们的速度、准确性以及我们在代码早期发现错误的能力。

当思考为什么我们需要测试我们的 API 时,您的脑海中可能会出现许多问题!尽管测试驱动开发看起来很简单,但它是开发人员可能经历的最困难和最顽皮的生命周期之一。最终,我们测试路由和处理程序的方式决定了我们的数据管理生命周期的进行方式。这就是KushoAI出现的时候。

说实话,我在发现可以帮助简化我的开发周期的人工智能代理时偶然想到了KushoAI,我向你保证。 “测试我的工具时,后端工程师的生活从未如此简单”。但 KushoAI 到底是什么?这只是“那些被过度炒作的人工智能工具,只是存在吗?它真的有用吗?如果是,那么如何?最重要的问题是:“是什么让 KushoAI 优于其他 AI 测试代理”。这就是为什么我决定创建一个博客来帮助您了解 KushoAI 的工作原理以及它提供的功能,这使得它与其他人不同!!

好吧,按照他们的文档中定义的书本定义:“KushoAI是一个用于API测试的AI代理,它为您的API生成详尽的测试套件 在几分钟内 – 您需要做的就是输入您的 API 信息,然后坐下来,让 KushoAI 找出您的 API 在生产中可能出现的实际场景,并为它们编写准备执行的测试。 ”

简单地说,您决定如何将输入提供给代理,并收到详细且独特的测试套件,它检查您的 API 将如何运行。是这样吗?显然不是,这就是为什么我在这里花时间写关于这个工具的博客。让我们看看 KushoAI 为工程师提供的最独特的功能。

API Testing Made Effortless : KushoAI


测试套件创建

(在 KushoAI 中创建测试套件的不同方法)

因此,该平台提供的第一个也是最令人兴奋的功能是为 API 选择数据输入以创建测试套件的多样性。 KushoAI 的文档指定:

“测试套件是 KushoAI 为您的 API 生成的测试集合。从高层次来看,这就是 KushoAI 上测试生成的工作原理:

  • 您提供 API 信息以使用下面指定的格式之一创建测试套件。
  • KushoAI 会查看您的 API 信息并找出此类 API 可能出现的问题。
  • 根据这些信息,KushoAI 提出了测试(包括场景和执行测试所需的 API 负载),这些测试将在该 API 的测试套件中提供。”

KushoAI 提供了 4 种主要方法来帮助您为测试生成提供 API 输入:

  1. 手动输入API详细信息
  2. 导入 OpenAPI 规范
  3. 导入邮递员收藏
  4. 复制并粘贴 cURL 命令

API Testing Made Effortless : KushoAI

在这4种方法中,我最喜欢的方法一直是导入邮递员收藏。不过,我想一一简单描述一下所有方法:

a) 手动输入 API 详细信息

由于其简单且易于理解,这是迄今为止该平台上最常用的方法之一。您需要知道的是 API 端点的设计方式,包括 端点 URL标头路径参数查询参数、以及您的特定 API 请求的 请求正文。输入此信息后,剩下要做的就是单击“生成”,然后 BOOM!! 只需几分钟,您的 API 测试就生成了。

现在,一个常见的问题可能是:如果您不熟悉这些术语,那么这些参数到底是什么?别担心——KushoAI 已经帮您解决了。该平台使用虚拟 API 示例对这些参数进行了清晰的解释,以便于理解。此外,KushoAI 还提供了创建 API 套件的功能,类似于 Postman 中集合的工作方式。

API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI

b) 导入 OpenAPI 规范

在我们的生活中,我们都曾经使用过像 Swagger 这样的服务作为我们的 API。如果您已经将 API 托管在 Swagger 上,那么最好的办法是将您的 JSON 直接导入 KushoAI,然后 KushoAI 使用内部解析器来获取有关您的 API 的所有信息以及 JSON 中列出的所有端点。此外,KushoAI 还为您提供了一个选项,仅选择您想要测试的端点。接下来是检查端点 URL,然后就可以开始了。只需点击生成并返回网站即可放松,而 KushoAI 会为您完成所有工作。下面显示了其工作原理的直观表示:

API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI

c) 从 Postman Collections 导入

我最喜欢的功能之一是能够从 Postman Collections 导入,这很大程度上归功于我对 Postman 的广泛使用。以前,我会使用必要的 方法 和参数手动输入端点。然而,我真正想要的是将这些 API 调用直接集成到我的测试中,这就是我发现 KushoAI 的原因。

这就是多么简单:

  1. 将 Postman 集合导出为 JSON 文件。
  2. 将 JSON 文件上传到 KushoAI。
  3. 就像导入 OpenAPI 规范时一样,选择需要生成测试的所需参数。
  4. 如果您有任何可选参数,例如身份验证令牌、请求等,请在下一个弹出窗口中输入详细信息。
  5. 点击“生成”,然后坐下来,放松,让 KushoAI 发挥其魔力。

API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI

d) 使用 cURL 命令导入

KushoAI 还为您提供了导入curl 命令并直接为您创建测试的选项。下面给出了为其创建测试的现实世界适用的 cRUL 命令的简单示例。

curl -v -X POST \
    -F 'hostname=docker' \
    -F 'modelid=5000000002' \
    -F 'sitegroupid=1' \
    -F 'siteid=772' \
    -F 'sitename=Niwot Ridge Forest/LTER NWT1 (US-NR1)' \
    -F 'pft[]=temperate.coniferous' \
    -F 'start=2004/01/01' \
    -F 'end=2004/12/31' \
    -F 'input_met=5000000005' \
    -F 'email=' \
    -F 'notes=' \
    'http://pecan.localhost/pecan/04-runpecan.php'
登录后复制

KushoAI Workbench 和 API 信息

KushoAI 让访问和管理 API 信息变得异常简单,提供对过滤器计数和详细API 信息等数据的洞察。 KushoAI 处理完您的 API 详细信息后,通常只需几分钟即可为您的 API 集合生成功能齐全的测试套件,以供执行。

但是如果您需要微调生成的测试用例以适应特定场景怎么办?不用担心 - KushoAI 为您提供了一个易于使用的界面,允许您修改请求详细信息并根据您的具体需求定制测试。

In addition to customization, KushoAI offers parallel computation and API calls, a feature that significantly reduces latency and boosts efficiency. This is one of the most impressive features KushoAI brings to the table, allowing you to test APIs faster and with greater precision.

However, when I say "one of the most impressive," I truly mean it, because KushoAI offers even more. You can automatically generate AI Assertions for each API request using Generative AI, which, in my opinion, is the standout feature of the platform. You can even integrate custom assertions, a feature that I haven’t seen work as quickly or effectively anywhere else.

Below are some examples of requests I processed using KushoAI, demonstrating how its services work. For this, I used a custom endpoint for the WeatherAPI to showcase KushoAI’s capabilities. The ability to easily integrate with your own custom assertions is a game-changer, offering unmatched flexibility and speed. Below are some assertions which were automatically generated using KushoAI's inbuilt Generative AI :

expect(response.response.location.name, "name should exist").to.exist;
expect(response.response.location.name, "name should be a string").to.be.a('string');
expect(response.response.location.region, "region should exist").to.exist;
expect(response.response.forecast.forecastday[0].hour[0].gust_kph, "gust_kph should be a number").to.be.a('number');
expect(response.response.forecast.forecastday[0].hour[0].uv, "uv should exist").to.exist;
expect(response.response.forecast.forecastday[0].hour[0].uv, "uv should be a number").to.be.a('number');
expect(response.statusCode, "statusCode should exist").to.exist;
expect(response.statusCode, "statusCode should be a number").to.be.a('number');
登录后复制

API Testing Made Effortless : KushoAI
API Testing Made Effortless : KushoAI

Workspaces and Collaboration

KushoAI offers a robust Workspaces feature that enables seamless collaboration among users, allowing teams to work together efficiently on API collections. This feature is especially useful for larger teams or projects where multiple individuals need to contribute to the same API testing suite, fostering real-time collaboration and making the development process smoother.

If you're familiar with GitHub, you'll find this functionality quite similar. Just as GitHub allows multiple developers to collaborate on code, KushoAI enables teams to work simultaneously on API collections, share test cases, and address the same issues without stepping on each other’s toes.

This Spectacular feature helps teams stay in sync, reducing bottlenecks and improving productivity. By centralizing the workspace and offering easy access to shared projects, KushoAI streamlines the API testing workflow, making it easier for users to track changes, provide feedback, and enhance the overall quality of their API services.

Whether you're working with a small team or managing a large project with many contributors, KushoAI ensures that collaboration is as efficient and frictionless as possible. With real-time updates and shared access to API collections, it takes teamwork in API testing to a whole new level. You can also manage your API Keys for further integrations and CI automation (which we will discuss a bit later) along with Environment Variables to store your secrets.

KushoAI's Workbench provides a more sophisticated and user-friendly interface than Postman's, allowing for greater flexibility and control during API testing. While Postman is well-known for its simplicity and ease of use, KushoAI goes above and beyond with capabilities such as custom test case generation, real-time modification of API requests, and parallel test execution, all of which greatly speed up the testing process. KushoAI's Workbench is built with Generative AI at its heart, allowing it to automatically develop extensive test cases across numerous scenarios—something Postman often restricts to simple checks like response status and time. Furthermore, KushoAI delivers extensive insights into the data coming via your APIs, allowing users to select and analyse results more accurately.

Integration in your CI/CD Pipelines

KushoAI offers seamless integration with your CI/CD pipelines, providing automated, real-time test generation and execution, without the need for any manual intervention. This integration ensures that every time a new commit is pushed or a change is made, KushoAI automatically runs tests to validate your API’s functionality, performance, and security.

Currently available as part of KushoAI’s Enterprise plan, this feature is designed for organizations that need continuous testing at scale. By incorporating KushoAI into your CI/CD workflow, you can ensure that every API update is thoroughly tested, reducing the likelihood of bugs and security vulnerabilities slipping into production.

KushoAI also supports GitHub Actions, making it easy to integrate API testing directly into your GitHub-based workflows. This allows your development and testing teams to catch issues early in the development process, improving overall efficiency and reducing the time spent on manual testing.

Automating your API testing as part of a CI/CD pipeline not only enhances testing performance but also significantly boosts security. Every change is automatically validated, meaning you can deploy confidently knowing your APIs have been tested at every stage of the development lifecycle. This eliminates potential security risks caused by human error, offering a reliable safeguard against bugs and vulnerabilities.

For more detailed information or to discuss how CI/CD integration can benefit your organization, the KushoAI team is available to provide consultation and support. Below is a visual representation of how the integration works within a typical pipeline:

Test Reports.

Once your test suites are completed, KushoAI will notify you when the testing process is complete, allowing you to focus on other things without having to manually monitor the tests. This is especially valuable for teams with many priorities, since it guarantees that your time is used efficiently while KushoAI does the testing.

In addition to alerts, KushoAI offers a real-time view of your test suite's generation status. You can simply follow the progress of your tests via the generation status page on the home tab, which keeps you updated on every stage of the process. This real-time visibility is critical for ensuring that no tests are left unfinished, providing you assurance that all APIs have been completely tested.

Once testing is completed, KushoAI provides export choices for test suites and results. You may export these reports in 'HTML' format, which provides a concise and well-organised overview of your test findings. These reports not only capture current tests, but they may also be saved for future reference, making it easier to follow progress or regression issues over time.

This functionality is extremely useful for companies trying to continually enhance their API speed. Reviewing these extensive reports allows you to discover possible issues, make appropriate changes, and retain a historical record of how your APIs have changed. KushoAI's reporting tools guarantee you always have access to actionable insights.

API Testing Made Effortless : KushoAI

API Testing Made Effortless : KushoAI

Image showing how data is exported in html format for further utilization

KushoAI's end-to-end testing (beta) features

Through the use of KushoAI's End-to-End (E2E) testing functionality, developers may replicate real-world processes by sequentially testing numerous API interactions to make sure they perform as intended. Engineers may use this functionality to cover complicated situations involving several endpoints, offering insights into the behaviour of your APIs in production environments. E2E testing offers many features, some of the most prominent features are:

  1. API Selection for Testing: - Users can add new APIs or pick existing ones to the test suite. For example, selecting "Weather Forecast API for Gorakhpur" as displayed in the image demonstrates that several endpoints and functions may be coupled to replicate a real-world scenario.

  2. Workflow Automation: - The "Run" and "Save Workflow" buttons enable users to develop, run, and store end-to-end tests for reuse. You may create processes that test APIs in the same order in which a real user would interact with them.

  3. Collaboration and Customization: - The Workspace feature in the top-right corner helps teams cooperate on processes and maintain test environments efficiently.

  4. User-Friendly Interface: The UI is intended to provide straightforward API administration, allowing users to quickly switch between adding new APIs and selecting pre-configured ones for testing. It also supports parallel API execution and real-time scenario validation.

API Testing Made Effortless : KushoAI

Images demonstrating UX flow of KushoAI's E2E testing (BETA)

KushoAI 与 Postman:生成测试

有人可能会想,既然 Postman 也提供生成测试,为什么还要选择 KushoAI?答案很简单:KushoAI 提供更全面、更智能的测试体验。 Postman 根据响应时间和状态代码等有限因素生成测试,而 KushoAI 会在所有可能的测试场景中生成测试,无论您的集合的具体情况如何。

这是一个游戏规则的改变者。 Postman 经常限制其生成的测试的范围,严重依赖于预定义的条件。相比之下,KushoAI 采用更稳健的方法,确保您的 API 在更广泛的条件下进行测试,包括 Postman 可能忽略的边缘情况和性能瓶颈。

为了说明这一点,我在本地主机后端服务器上运行模拟来检查用户数据和响应,类似于之前使用天气 API 的示例。结果清楚地表明,KushoAI 的生成测试框架不仅提供了更多的测试用例,而且还深入研究了 Postman 的方法完全忽略的潜在故障点和错误场景。 KushoAI 能够在所有功能层(从端点稳定性到数据完整性)创建全面的测试,这证明了其卓越的覆盖范围和可靠性。

此外,KushoAI 的 生成式 AI 专为识别 API 中的细微问题而量身定制,提供符合您特定需求的智能断言和自定义测试用例 - 这是 Postman 所缺乏的。借助 KushoAI,您不仅可以根据表面指标进行测试,还可以根据实际情况进行测试。您正在验证整个 API 生命周期,从安全漏洞到现实世界的压力测试。

简而言之,KushoAI 优于 Postman 等其他生成测试解决方案,确保API 的每个方面都经过严格测试,提供更深入的见解、更大的灵活性和更可靠的结果。证据在于通过 PostmanKushoAI 生成的测试,它展示了 KushoAI 的高级测试引擎如何为您提供一定程度的覆盖范围,使其在竞争中脱颖而出。

API Testing Made Effortless : KushoAI

API Testing Made Effortless : KushoAI

KushoAI 决定测试包含数据条件的场景,而 Postman 决定测试包含错误代码和正文内容的场景。

结论

除了是一个自动化测试工具之外,KushoAI 也是一个强大并且比其他平台优越平台,它简化了开发和测试 API 的整个过程。它通过采用尖端的人工智能技术,消除了与 API 测试相关的繁琐工作,使开发人员能够专注于真正重要的事情:创造力。从无缝 CI/CD 集成到协作工作区和自定义测试生成,它还提供了提高生产力、减少错误和加速交付所需的一切。无论您是小型团队还是大型企业,KushoAI 的功能都能确保您的 API 得到彻底、安全、高效的测试。有 KushoAI 在您身边,API 测试不仅变得更容易,而且更智能。

以上是API 测试变得轻松:KushoAI的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:dev.to
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!