端-到-端测试 (E2E)
一句话解释
E2E 测试 drives 真实浏览器通过你的 application 只是如 用户会, 验证完整 flow 工作从 UI 到数据库 and 后面.
用大白话说
E2E 测试是 大多数 realistic 测试你 能编写. 它打开真实浏览器, 导航到 你的 app, 点击 buttons, fills 表单, and 检查那个正确 things happen — 精确地如 human 用户会.
Think 的它 as robot tester 那个 follows script: 'go 到登录 page, 类型用户名, 类型密码, 点击登录, 检查那个 dashboard appears.' 它测试一切: UI, backend, 数据库, network — 整个端-到-端 flow.
E2E 测试是 powerful 但 expensive: 它们're 慢 (seconds, 不 milliseconds), brittle (break on minor UI 更改), and 困难到 maintain. Use 它们 sparingly for 关键用户 flows, 不 for 每个可能场景.
示例
javascript
// Playwright E2E test
test('user can log in', async ({ page }) => {
await page.goto('https://app.example.com/login');
await page.fill('#username', 'alice');
await page.fill('#password', 'secret');
await page.click('button[type="submit"]');
await expect(page).toHaveURL(/dashboard/);
});这个测试打开真实浏览器, 导航到 登录 page, fills in credentials, and 验证 redirect 到 dashboard.
常见混淆
容易混淆的对象: Integration 测试
关键区别: E2E 测试 go 通过 UI and 整个 stack; integration 测试检查内部模块连接不使用 UI.
相关术语
相关资源
相关课程
- E2E 测试
端-到-端测试 overview.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。