简体   繁体   English

使用 Cypress 或 React 测试库进行集成测试?

[英]Integration test with Cypress or React Testing Library?

I'm new to testing and as I understand, integration tests are aimed to test a bunch of components and how they interact with each other.我是测试新手,据我了解,集成测试旨在测试一堆组件以及它们如何相互交互。

But if in a project we use both Cypress for E2E and React testing library for unit testing, which one to use for integration tests, and what are the pros and cons?但是如果在一个项目中我们同时使用 Cypress 进行 E2E 和 React 测试库进行单元测试,那么使用哪一个进行集成测试,优缺点是什么?

I would recommend using React testing library (RTL) since integration testing is more granular and does not require the entire application to run.我建议使用React 测试库(RTL),因为集成测试更加精细,并且不需要运行整个应用程序。

The main benefit of Cypress is that it tests against real browsers which makes it great for ensuring your E2E flows work as intended. Cypress的主要优点是它可以针对真实的浏览器进行测试,这非常有助于确保您的 E2E 流程按预期工作。 While Cypress is fast, it has to do a lot of additional work compared to RTL.虽然 Cypress 速度很快,但与 RTL 相比,它还需要做很多额外的工作。 I do think Cypress is best for just E2E testing, specifically the high value paths in your application.我确实认为赛普拉斯最适合 E2E 测试,特别是应用程序中的高价值路径。

Cypress recently introduced component testing, https://docs.cypress.io/guides/component-testing/introduction Cypress 最近推出了组件测试, https://docs.cypress.io/guides/component-testing/introduction

Running test in the browser environment makes it easier to understand what's going on within the test thanks to visual feedback from the browser.由于来自浏览器的视觉反馈,在浏览器环境中运行测试可以更容易地理解测试中发生了什么。

Such approach also allows to tests things like drag and drop, which is difficult to achieve with JSDom.这种方法还允许测试诸如拖放之类的东西,这是用 JSDom 很难实现的。

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

相关问题 使用 jest 和 react 测试库进行单元和集成测试的 TRPC 测试包装器 - 客户端模拟 - TRPC Test Wrapper for unit and integration testing using jest and react testing library - client mock 对文本输入使用去抖动的 React 组件执行集成测试(使用 React 测试库) - Perform an integration test on a react component where the text input uses debounce (using react testing library) Jest / React 测试库:是否可以像 Cypress 一样监视并等待 GraphQL 查询? - Jest / React Testing Library: Is it Possible to Spy on and Wait GraphQL Queries as with Cypress? 赛普拉斯:在离线模式下测试 React 应用程序会导致测试挂起 - Cypress: testing React app in offline mode causes test to hang 使用 Cypress 和 React 测试工作流程 - Testing workflow with Cypress and React 使用 React 测试库进行测试下拉 - Test Drop Down With React Testing Library 使用react-testing-library进行测试卸载 - Test unmounting with react-testing-library React 测试库:简单的路由测试错误 - React Testing Library: Simple routing test error 使用反应测试库进行下一个 seo 测试 - Next seo test with react testing library 如何使用 React 测试库测试 HTML 内容 - How to test HTML content with React testing library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM