> ## 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.

# 一夜之内测完 8 个尚未测试的模块

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

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>;
};

<UseCaseHero title="一夜之间测试完 8 个未测试模块" description="在夜间启动 8 个并行 Devin 会话——每个会话为一个测试覆盖率较低的模块编写单元测试，并在早上前创建一个 PR。" prompt="运行我们的测试覆盖率报告，找到 8 个代码行覆盖率低于 50% 的模块，并启动一组并行 Devin 会话——每个模块一个会话——每个会话使用我们的测试编写 Playbook 将覆盖率提升到 80% 以上。为每个模块分别创建一个 PR。" category="Devin 优化" features="高级, Playbook" agent="advanced" intent="batch" />

<div className="uc-detail-wrapper">
  <Tip>不想手动设置？将此页面的链接粘贴到 Devin 会话中，让它为你完成所有设置。</Tip>

  <Steps>
    <Step title="创建测试编写指南">
      你的电商 monorepo 中有 30 多个模块，但只有少数拥有有效的测试覆盖率。你希望将整体覆盖率从 44% 提升到 80%——从覆盖率最差的 8 个模块开始。在启动并行会话之前，你需要一个 [Playbook (操作手册) ](/zh/product-guides/creating-playbooks)，确保这 8 个会话都以相同的方式编写测试。

      让 Devin 为你创建这个 Playbook——只需在任意会话中描述你的测试规范：

      <PromptBlock agent="advanced" intent="create">
        ```txt Create a test-writing playbook theme={null}
        Create a playbook for writing unit tests in our monorepo. It should enforce:
        1. Use Vitest with TypeScript. Import from `vitest`.
        2. Follow the AAA pattern (Arrange, Act, Assert).
        3. Mock external dependencies — never call real APIs, databases, or third-party services.
        4. Use test helpers from `src/test/helpers.ts` (e.g., `createMockUser()`, `setupTestDB()`).
        5. Place test files at `{module}/__tests__/{filename}.test.ts`.
        6. Cover success paths, error paths, and edge cases for every exported function.
        7. Run `npm test -- --coverage --reporter=json` and verify the module exceeds 80% line coverage.
        8. Open a PR with the new tests. Include the before/after coverage numbers in the PR description.
        ```
      </PromptBlock>

      这个 Playbook 会成为每个并行会话的共享指令集。你也可以添加关于测试工具、mock 模式或任何项目特有细节的 [Knowledge](/zh/product-guides/knowledge) 条目 (例如，"在 `afterEach` 中始终调用 `resetMocks()`") 。
    </Step>

    <Step title="在下午 6 点启动 8 个并行会话">
      在你结束一天工作时，从 [Devin 主页](https://app.devin.ai/?utm_source=docs\&utm_medium=use-case-gallery) 新建一个 Devin 会话，并描述这个批处理任务。

      1. 从下拉菜单中选择你的测试编写 playbook
      2. 在提示中描述任务：

      <PromptBlock agent="advanced" intent="batch">
        ```txt 夜间测试覆盖率批处理 — 8 个模块 theme={null}
        在我们的代码仓库中运行 `npm run test:coverage`。找出行覆盖率最低的 8 个模块
        （跳过任何位于 src/generated/ 下的内容）。

        对每个模块，使用选定的 playbook 启动一个并行 Devin 会话。
        每个会话应当：
        - 阅读该模块的源代码和任何已有测试
        - 编写新的单元测试，将行覆盖率提高到 80% 以上
        - 运行完整测试套件以确认没有功能被破坏
        - 发起一个 PR，包含新的测试文件以及变更前/后的覆盖率对比摘要
        ```
      </PromptBlock>

      3. 查看拟创建的会话 — Devin 会列出每个模块及其当前覆盖率，并确认将要创建哪些会话：

      ```
      建议的会话（8 个模块，覆盖率均低于 50%）：
        1. src/services/PaymentService — 31% coverage
        2. src/services/UserService — 38% coverage
        3. src/api/routes/billing — 42% coverage
        4. src/middleware/auth — 44% coverage
        5. src/services/NotificationSvc — 47% coverage
        6. src/components/Checkout — 49% coverage
        7. src/utils/validation — 51% coverage
        8. src/services/SearchService — 53% coverage

      启动 8 个并行会话？(y/n)
      ```

      4. 批准该批次后合上你的笔记本电脑。所有 8 个会话会在不同的 Devin 机器上同时启动，每个都会独立地按照你的操作手册执行。
    </Step>

    <Step title="一觉醒来就有 8 个 PR">
      到早上时，每个会话都已完成并创建了各自的拉取请求 (PR) 。你将在代码仓库中看到 8 个 PR，每个都包含新的测试文件和覆盖率摘要：

      ```
      Module                       | Before | After  | PR     | Status
      -----------------------------|--------|--------|--------|--------
      src/services/PaymentService  |  31%   |  87%   | #412   | Ready
      src/services/UserService     |  38%   |  84%   | #413   | Ready
      src/api/routes/billing       |  42%   |  91%   | #414   | Ready
      src/middleware/auth           |  44%   |  82%   | #415   | Ready
      src/services/NotificationSvc |  47%   |  85%   | #416   | Ready
      src/components/Checkout      |  49%   |  83%   | #417   | Ready
      src/utils/validation         |  51%   |  93%   | #418   | Ready
      src/services/SearchService   |  53%   |  86%   | #419   | Ready

      Overall coverage: 44% -> 68% (+24 pts across targeted modules)
      ```

      可以按任意顺序合并这些 PR——由于每个会话只会向其所属模块添加新的测试文件，几乎不会产生冲突。如果两个会话修改了共享的测试辅助工具，请手动解决冲突，或让 Devin 来修复。
    </Step>

    <Step title="为下一梯队再运行一批">
      单靠一晚上的批处理，无法让整个代码库的覆盖率达到 80% 的目标。第二天晚上，再为下一层级的模块跑一轮补充批处理：

      <PromptBlock agent="advanced" intent="batch">
        ```txt 第二晚覆盖率批处理 theme={null}
        当前整体覆盖率为 68%，目标是 80%。请再次运行覆盖率报告，
        找出接下来覆盖率最低的 6 个模块（跳过任何已经高于
        80% 的模块），并按照相同的测试编写流程再启动一批测试。
        ```
      </PromptBlock>

      你也可以从单元测试转向针对关键用户流程的集成测试：

      <PromptBlock agent="advanced" intent="batch">
        ```txt 关键流程的批量集成测试 theme={null}
        找出我们最关键的 5 个用户流程（注册、登录、结账、
        重置密码、注销账户）。为每个流程启动一个并行会话，
        使用 Playwright 编写端到端集成测试。每个会话都应覆盖
        正常路径以及 2–3 种错误场景。
        ```
      </PromptBlock>

      两晚的并行会话就能把代码库的覆盖率从不足 50% 提升到超过 80%——这些工作如果由工程师手动完成，需要几周的专门投入。
    </Step>
  </Steps>
</div>
