How to Run End-to-End Tests with Claude Code
How to Run End-to-End Tests with Claude Code
如何使用 Claude Code 运行端到端测试
Agentic AI: How to Run End-to-End Tests with Claude Code. Increase the effectiveness of your coding agents through end-to-end testing. Eivind Kjosbakken, Jul 6, 2026, 8 min read. 智能体 AI:如何使用 Claude Code 运行端到端测试。通过端到端测试提高编码智能体的效率。作者:Eivind Kjosbakken,2026 年 7 月 6 日,阅读时间 8 分钟。
In this article, I’ll discuss how to use calling agents to perform end-to-end testing to make implementations even more effective. 在本文中,我将讨论如何利用调用智能体(calling agents)执行端到端测试,从而使代码实现更加高效。
Coding agents like Claude Code can be used for a wide variety of tasks. The number one task you might think of is to actually implement code. However, there are also so many other tasks that you can use them for. You can use them to analyze documents, navigate your computer, use the browser, perform spreadsheet calculations, and so on. My point is that coding agents can basically be used to perform all tasks on your computer. 像 Claude Code 这样的编码智能体可以用于各种各样的任务。你首先想到的任务可能就是编写代码。然而,它们还可以胜任许多其他工作。你可以利用它们分析文档、操作电脑、使用浏览器、进行电子表格计算等等。我的观点是,编码智能体基本上可以用来执行你电脑上的所有任务。
The task I’ll cover today is running end-to-end tests with Claude Code. End-to-end tests are basically tests where you make the coding agent open a browser and click through it and test its implementations completely. In that way, an alternative testing scheme could be unit tests or integration tests. End-to-end tests are great because they test the application just like how a user would use the application, which ensures that you are able to properly test the application and discover issues that the user might experience. 今天我要介绍的任务是使用 Claude Code 运行端到端测试。端到端测试本质上是让编码智能体打开浏览器,通过点击操作来全面测试其代码实现。与之相对的测试方案可以是单元测试或集成测试。端到端测试的优势在于,它模拟了用户的真实使用场景,从而确保你能正确测试应用程序,并发现用户可能会遇到的问题。
I’ll discuss how to run end-to-end tests with Claude Code, why you should be running end-to-end tests, and specific techniques you can use to make end-to-end testing effective. 我将讨论如何使用 Claude Code 运行端到端测试,为什么要进行端到端测试,以及如何通过特定技巧提高端到端测试的有效性。
Why run end-to-end tests with Claude Code
为什么要使用 Claude Code 运行端到端测试
First of all, I’d like to cover why you should care about this topic. The reason you should run end-to-end tests with Claude Code is simply that it’s an effective way of testing your code implementations. After coding agents became extremely powerful, most notably after the release of Claude Opus 4.5, a new bottleneck that arose was testing the code that’s been implemented. 首先,我想谈谈你为什么要关注这个话题。你应该使用 Claude Code 运行端到端测试的原因很简单:这是一种测试代码实现的有效方法。在编码智能体变得极其强大之后(尤其是 Claude Opus 4.5 发布后),出现了一个新的瓶颈,那就是对已实现代码的测试。
Before coding agents, the bottleneck was mostly producing the code because it took an engineer a large amount of time to produce the code to either implement a bug fix or implement a new feature. However, this has shifted now that we have coding agents because they’re so effective at implementing new code. The new bottleneck now is basically testing the code. And you don’t want to be manually testing all the code that coding agents implement, which is why you should be using end-to-end tests. 在编码智能体出现之前,瓶颈主要在于代码的编写,因为工程师需要花费大量时间来编写代码以修复 Bug 或实现新功能。然而,随着编码智能体的出现,情况发生了转变,因为它们在实现新代码方面非常高效。现在的瓶颈基本上变成了代码测试。你肯定不想手动测试编码智能体编写的所有代码,这就是你应该使用端到端测试的原因。
This is basically making the coding agent fully test its own code before you verify the work. Running end-to-end tests is super powerful, and it basically gives the models a way to verify their own work, which is extremely powerful and makes them more likely to do one-shot implementations, which will save you a lot of time as an engineer. 这本质上是让编码智能体在人工验证之前先全面测试自己的代码。运行端到端测试非常强大,它为模型提供了一种验证自身工作的方法,这极大地提高了它们“一次性成功”实现功能的可能性,从而为你作为工程师节省大量时间。
How to run end-to-end tests with Claude Code
如何使用 Claude Code 运行端到端测试
Now it’s time to discuss how to actually run end-to-end tests. The good thing about coding agents is that you can use them to also set up end-to-end testing. In short, all you’re gonna do to run end-to-end tests is basically to have a coding agent and give that coding agent access to the browser and also login access to the tool that you’re testing. 现在是时候讨论如何实际运行端到端测试了。编码智能体的好处在于,你也可以利用它们来设置端到端测试。简而言之,运行端到端测试的方法就是:让编码智能体获得浏览器访问权限,以及你所测试工具的登录权限。
Once you’ve done this, you can simply ask the coding agent to perform end-to-end tests before considering a task is done. This end-to-end testing is super simple, but there are a lot of ways to optimize end-to-end testing both to make it more effective and make the agents better at performing the end-to-end testing. 完成这些后,你只需要求编码智能体在认为任务完成之前执行端到端测试即可。这种端到端测试非常简单,但有很多方法可以对其进行优化,既能提高测试效率,又能让智能体更好地执行测试。
I’ll also discuss some different situations where you might want to run end-to-end testing. For example, you might want to run it: After implementing a new feature, after solving a bug, or on a daily schedule to check that everything in the application is working as expected. 我还将讨论一些你可能需要运行端到端测试的不同场景。例如,你可能希望在以下情况下运行它:实现新功能后、修复 Bug 后,或者按每日计划运行,以检查应用程序中的一切是否按预期工作。
My end-to-end testing prompt
我的端到端测试提示词 (Prompt)
First of all, I’ll cover the prompt I use to perform end-to-end testing (and, in general, the prompt I use to ensure my coding agents have completed their work successfully). 首先,我将介绍我用于执行端到端测试的提示词(以及我通常用来确保编码智能体成功完成工作的提示词)。
“Implement everything I asked for. Verify it end to end by clicking through the browser using the Playwright MCP. It’s not acceptable to test the application only through integration tests. You need to actually click around the app. Continue like this until it works. Fix any issues if you encounter them then do an end to end test again. Run codex exec and run the review skill with codex and make him approve it and iterate until codex has approved it. When codex has approved it, get this to dev, and then test end to end in dev again. Continue until its running fine in dev.” “实现我要求的所有内容。使用 Playwright MCP 通过浏览器点击操作进行端到端验证。仅通过集成测试来测试应用程序是不可接受的。你需要实际在应用中进行点击操作。持续进行直到功能正常。如果遇到任何问题,请修复它们,然后再次进行端到端测试。运行 codex exec 并使用 codex 的 review 技能,让他批准,并不断迭代直到 codex 批准为止。当 codex 批准后,将其部署到开发环境(dev),然后在开发环境中再次进行端到端测试。持续进行直到它在开发环境中运行良好。”
This is the daily prompt I use to get stuff to dev. So essentially, I explain a task to Claude Code. Then I run slash goal with the prompt that you see above. To make it super simple to write out this full prompt every time, I use the FluidVoice transcription tool, and I then say “complete merge test”. I then set up word replacement so that FluidVoice automatically swaps out the three words for the full prompt above. This makes it super simple for me to constantly prompt my agents to run the full end-to-end test.
这是我每天用来将代码推送到开发环境的提示词。本质上,我先向 Claude Code 解释任务,然后使用上述提示词运行 /goal 命令。为了避免每次都输入完整的提示词,我使用了 FluidVoice 转录工具,只需说“complete merge test”。我设置了词汇替换,让 FluidVoice 自动将这三个词替换为上述完整提示词。这使得我能够非常简单地持续提示智能体运行完整的端到端测试。
Playwright MCP
Playwright MCP
First of all, with Claude Code, they have a built-in Chrome MCP you can use to give Claude access to Chrome, and it can thus access the browser. However, I personally prefer the Playwright MCP because I believe that it makes the agent perform better when interacting with the browser. To install the Playwright MCP, you can simply prompt Claude Code to install it for you. Restart the Claude Code session, and it will have access to the Playwright MCP, which you can use to interact with the browser. 首先,Claude Code 内置了一个 Chrome MCP,你可以用它让 Claude 访问 Chrome,从而操作浏览器。然而,我个人更喜欢 Playwright MCP,因为我认为它能让智能体在与浏览器交互时表现更好。要安装 Playwright MCP,你只需提示 Claude Code 为你安装即可。重启 Claude Code 会话,它就能访问 Playwright MCP,你可以用它与浏览器进行交互。
It’s also worth noting that there are a lot of tools out there that you can use to interact with the browser, and that Playwright MCP is simply the tool that I’m using on a daily basis. 值得注意的是,市面上有很多工具可以用来与浏览器交互,而 Playwright MCP 只是我日常使用的工具。
The /goal command
/goal 命令
The slash goal command is also extremely powerful.
/goal 命令也非常强大。