[英]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.