> ## Documentation Index
> Fetch the complete documentation index at: https://nvd-54.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 测试

> LangChain 智能体的测试策略，包括单元测试、集成测试和轨迹评估。

智能体应用让大语言模型（LLM）自行决定下一步操作来解决问题。这种灵活性很强大，但模型的黑箱特性使得很难预测对智能体某一部分的调整会如何影响整体。要构建生产级智能体，全面的测试至关重要。

以下是测试智能体的几种方法：

* **单元测试**使用内存中的模拟对象隔离地测试智能体中小的、确定性的部分，以便你能快速且确定地断言确切行为。
* **集成测试**使用真实的网络调用测试智能体，以确认各组件协同工作、凭证和模式匹配、以及延迟可接受。
* \*\*评估（Evals）\*\*使用评估器来评估智能体的执行轨迹，方式包括确定性匹配或 LLM 评委。

智能体应用倾向于更多地依赖集成测试，因为它们将多个组件链接在一起，并且由于 LLM 的非确定性本质而必须处理不稳定性。

<Tip>
  使用 [LangSmith](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=oss-langchain-test-index) 大规模运行评估、跟踪结果并比较实验。请参阅[评估 LLM 应用](/langsmith/evaluate-llm-application)开始使用。
</Tip>

<CardGroup cols={1}>
  <Card title="单元测试" icon="flask" href="/oss/javascript/langchain/test/unit-testing" arrow>
    使用模拟聊天模型和内存持久化来测试智能体逻辑，无需 API 调用。
  </Card>

  <Card title="集成测试" icon="plug" href="/oss/javascript/langchain/test/integration-testing" arrow>
    使用真实的 LLM API 测试你的智能体。组织测试、管理密钥、处理不稳定性和控制成本。
  </Card>

  <Card title="评估" icon="scale" href="/oss/javascript/langchain/test/evals" arrow>
    使用确定性匹配或 LLM 评委评估器来评估智能体轨迹。
  </Card>
</CardGroup>

***

<div className="source-links">
  <Callout icon="terminal-2">
    [连接这些文档](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/test/index.mdx)或[提交 issue](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
