> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 测试与重构

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<div id="overview">
  ## 概览
</div>

Devin 可以分析现有代码库，识别可改进的部分，或根据你提供的重构需求执行变更，在不影响现有功能的前提下完成修改。

<div id="common-use-cases">
  ## 常见用例
</div>

1. 编写并扩展测试覆盖范围
2. 代码重构与优化
3. 开发和修改 API 端点
4. 性能优化
5. 代码审查与质量保证
6. 通过 [API 参考文档](/zh/api-reference/overview) 实现自动化测试工作流

<div id="example-prompts">
  ## 示例提示
</div>

<AccordionGroup>
  <Accordion title="编写单元测试" icon="magnifying-glass">
    <PromptBlock>
      ```txt 编写单元测试 theme={null}
      请先完成 https://github.com/markedjs/marked 的环境配置，使用命令行工具并带上 --output/-o 参数，然后添加一个单元测试来测试 --output 参数。
      bin.test.js 中应该已经有类似的测试用例，你可以在此基础上新增。
      ```
    </PromptBlock>
  </Accordion>

  <Accordion title="端点重构" icon="gear-code">
    <PromptBlock>
      ```txt 端点重构 theme={null}
      当前当用户向 <endpoint> 发送 POST 请求时，我们会 <描述该端点的行为>。基于 <解释原因>，最好将该端点拆分为两个独立的端点。
      <描述第一个端点应该完成的功能>。
      <描述第二个端点应该完成的功能>。
      通过 <说明 Devin 应该如何测试每个端点以验证实现是否走在正确方向上> 进行测试。
      ```
    </PromptBlock>
  </Accordion>

  <Accordion title="通用重构" icon="code">
    <PromptBlock>
      ```txt 通用重构 theme={null}
      在 Slack 服务器中，将 AppRegistry 抽取重构到一个独立的文件中。
      ```
    </PromptBlock>
  </Accordion>
</AccordionGroup>

<div id="example-sessions">
  ## 示例会话
</div>

<div id="code-coverage-tutorial">
  ### 代码覆盖率教程
</div>

通过我们的详细教程，系统地学习如何提高测试覆盖率：

* 编写全面的单元测试
* 识别覆盖盲区
* 补充缺失的测试用例

[查看代码覆盖率教程](/zh/use-cases/tutorials/code-coverage)

<div id="connect4-code-refactor">
  ### Connect4 代码重构
</div>

一次完整的重构会话，展示了：

* 代码结构改进
* 组件拆分
* 性能优化
* 测试覆盖率提升

**查看会话：**
[https://app.devin.ai/sessions/8965de5e3ae0436985bf3dd2e1a5b4af](https://app.devin.ai/sessions/8965de5e3ae0436985bf3dd2e1a5b4af)
