• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdevelopment

platform-apex-test-run

プラグイン
salesforce-development
ソース
GitHub で見る ↗
説明

Apex テスト実行、カバレッジ分析(コードの検査範囲の測定)、およびテスト修正ループを 120 ポイントのスコアリングで実行します。 **次のような場合に使用:** ユーザーが Apex テストを実行する、コードカバレッジ(カバレッジを確認する、テスト失敗を修正する、または *Test.cls / *_Test.cls ファイルを操作する必要がある場合 **トリガー対象:** ユーザーが Apex テストを実行する、コードカバレッジを確認する、テスト失敗を修正する、または *Test.cls / *_Test.cls ファイルに触れた場合 **トリガー対象外:** Apex 本番用コード(platform-apex-generate を使用)、Agentforce(営業支援 AI)エージェント テスト(agentforce-test を使用)、Jest/LWC(軽量コンポーネント)テスト(experience-lwc-generate を使用)を作成する場合

原文を表示

Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user needs to run Apex tests, check code coverage, fix failing tests, or work with *Test.cls / *_Test.cls files. TRIGGER when: user runs Apex tests, checks code coverage, fixes failing tests, or touches *Test.cls / *_Test.cls files. DO NOT TRIGGER when: writing Apex production code (use platform-apex-generate), Agentforce agent testing (use agentforce-test), or Jest/LWC tests (use experience-lwc-generate).

ユースケース
  • Apexテストを実行する
  • コードカバレッジを確認する
  • テスト失敗を修正する
  • テストファイルを操作する
本文(日本語訳)

platform-apex-test-run: Salesforce テスト実行とカバレッジ分析

次のような場合に使用: ユーザーがApex テストの実行と失敗分析を必要とするとき — テストの実行、カバレッジの確認、失敗の解釈、カバレッジの改善、Salesforce コードの体系的なテスト修正ループの管理。

このスキルが担当する作業

platform-apex-test-run を使用するのは、以下の作業が含まれる場合です:

  • sf apex run test ワークフロー
  • Apex ユニットテストの失敗
  • コードカバレッジ分析
  • カバーされていない行と不足しているテストシナリオの特定
  • Apex コードの体系的なテスト修正ループ

以下の場合は別のスキルに委譲してください:

  • 本番用 Apex コードの作成またはリファクタリング → platform-apex-generate スキル
  • Agentforce エージェントのテスト → agentforce-test スキル
  • Jest を使用した LWC のテスト → experience-lwc-generate

最初に収集すべき必須情報

以下を確認または推定してください:

  • 対象組織のエイリアス
  • テスト範囲:単一クラス、特定メソッド、スイート、またはローカルテスト
  • カバレッジの目標値
  • ユーザーが診断のみを望むか、テスト修正ループまで行うか
  • テストデータ作成用ヘルパーが既に存在するか

推奨ワークフロー

1. テスト範囲を把握する

以下を特定します:

  • 既存のテストクラス
  • 対象となる本番用クラス
  • テストデータ作成ヘルパー / セットアップ補助ツール

2. まず最小限の有用なテストセットを実行する

失敗のデバッグ時は範囲を狭く始め、修正が安定してから拡大します。

3. 結果を分析する

焦点を当てるポイント:

  • 失敗したメソッド
  • 例外の種類とスタックトレース
  • カバーされていない行 / カバレッジが弱い領域
  • 失敗が不正なテストデータ、脆い検証、または壊れた本番ロジックのいずれに起因するか

4. 体系的な修正ループを実行する

コードやテストの品質に問題がある場合:

  • 必要に応じて platform-apex-generate スキルにコード修正を委譲
  • テストを追加または改善
  • より広い範囲のテストを実行する前に、焦点を当てたテストを再実行

5. カバレッジを意識的に改善する

以下をカバーしてください:

  • 正常系パス
  • 異常系 / 例外パス
  • 一括処理パス(必要に応じて 251 件以上のレコード)
  • 関連するコールアウト(外部システムへの呼び出し)または非同期パス

重要なルール

ルール 理由
デフォルトで SeeAllData=false を使用 テストの独立性を確保し、組織固有のデータへの依存を防止
すべてのテストは意味のある検証を必須とする 検証なしのテストは何も証明せず、偽りの信頼を生む
251 件以上のレコードで一括動作をテスト トリガーは 200 件単位でバッチ処理;251 件の場合は境界を越える
明確性が向上する場合は、ファクトリ / @TestSetup を使用 一箇所でのデータ作成の一貫性;テストメソッド間でロールバック
Test.startTest() と Test.stopTest() を非同期処理でペアで使用 非同期操作(キューバブル、フューチャー)が検証前に完了するのを保証
テスト内に組織依存の不安定な要素を隠さない 組織の状態に紐付いた断続的な失敗を防止

よくある落とし穴

問題 解決方法
ローカルではテストが成功するが、CI 組織で失敗 SeeAllData=true または組織固有のレコードへの未宣言の依存をチェック
リファクタリング後、カバレッジが予期せず低下 まずクラスレベルのテストに焦点を当て、次に RunLocalTests に拡大して確認
コールアウトテストで「Uncommitted work pending」エラー DML と HTTP コールアウトは Test.startTest() でラップせずに混在させることはできない
モックが機能しない コールアウトを行うコードの前に Test.setMock() が呼び出されていることを確認
@TestSetup データがテストメソッド内に存在しない @TestSetup データはテストメソッドごとにコミットされるため、再度クエリを実行;静的変数には保存しない
API バージョン 67.0 以上でアクセスレベルチェックが不十分 SOQL / DML スタックトレースで CRUD / FLS アクセスエラーをチェック;ユーザーモードの動作を意図する場合は割り当てられたパーミッションセットで System.runAs を使用、またはシステムアクセスが必要な場合は正当な理由を文書化した SYSTEM_MODE パスを指定

出力形式

完了時は、以下の順序で報告してください:

  1. 実行したテスト
  2. 成功 / 失敗のまとめ
  3. カバレッジ結果
  4. 根本原因の調査結果
  5. 修正または次回実行の推奨

推奨形式:

テスト実行: <範囲>
組織: <エイリアス>
結果: <成功 / 部分的 / 失敗>
カバレッジ: <パーセンテージ / 主要クラス>
問題: <最も重要な失敗>
次のステップ: <クラスを修正、テストを追加、範囲を再実行、または回帰テスト範囲を拡大>

スキル間の連携

必要な作業 委譲先 理由
本番コードの修正またはテストクラスの作成 platform-apex-generate スキル コード生成と修復
一括 / エッジケースのテストデータ作成 platform-data-manage 現実的なテストデータセット
更新されたテストを組織にデプロイ platform-metadata-deploy デプロイメントワークフロー
詳細な実行時ログを検査 platform-apex-logs-debug より詳しい失敗分析

リファレンスファイル一覧

ファイル 参照するタイミング
references/cli-commands.md sf apex run test コマンドのすべてのフラグ、出力形式、非同期実行、カバレッジコマンド
references/test-patterns.md テストクラステンプレート — 基本、一括(251+)、モックコールアウト、データファクトリパターン
references/testing-best-practices.md コアテスト原則 — AAA パターン、命名規則、一括、異常系、モック戦略
references/test-fix-loop.md エージェント型テスト修正ループの実装と失敗分析の判定フロー
references/mocking-patterns.md HttpCalloutMock、DML モック、StubProvider、セレクタモックパターン
references/performance-optimization.md テスト実行時間を短縮する技法 — DML モック、SOQL モック、ループ最適化
assets/basic-test.cls テンプレート:@TestSetup、正常系 / 異常系 / 一括 / エッジケースメソッド付きの標準テストクラス
assets/bulk-test.cls テンプレート:200 件のトリガーバッチ境界を越える 251+ レコードの一括テスト
assets/mock-callout-test.cls テンプレート:HttpCalloutMock を使用した HTTP コールアウトモック
assets/test-data-factory.cls テンプレート:作成および挿入ヘルパー付きの再利用可能な TestDataFactory
assets/dml-mock.cls テンプレート:IDML インターフェース + DMLMock 実装(データベース不要のユニットテスト)
assets/stub-provider-example.cls テンプレート:StubProvider ベースの依存性注入スタブ
scripts/parse-test-results.py ツール後フック — sf apex run test JSON 出力を解析して自動修正ループ向けに失敗をフォーマット

スコアガイド

スコア 意味
108+ 本番環境レベルの強力なテスト信頼度
96–107 良好なテストスイート(軽微なギャップあり)
84–95 許容範囲だが、カバレッジ / 検証を強化
< 84 基準以下;信頼する前に改訂が必要
原文(English)を表示

platform-apex-test-run: Salesforce Test Execution & Coverage Analysis

Use this skill when the user needs Apex test execution and failure analysis: running tests, checking coverage, interpreting failures, improving coverage, and managing a disciplined test-fix loop for Salesforce code.

When This Skill Owns the Task

Use platform-apex-test-run when the work involves:

  • sf apex run test workflows
  • Apex unit-test failures
  • code coverage analysis
  • identifying uncovered lines and missing test scenarios
  • structured test-fix loops for Apex code

Delegate elsewhere when the user is:

  • writing or refactoring production Apex → platform-apex-generate skill
  • testing Agentforce agents → agentforce-test skill
  • testing LWC with Jest → experience-lwc-generate

Required Context to Gather First

Ask for or infer:

  • target org alias
  • desired test scope: single class, specific methods, suite, or local tests
  • coverage threshold expectation
  • whether the user wants diagnosis only or a test-fix loop
  • whether related test data factories already exist

Recommended Workflow

1. Discover test scope

Identify:

  • existing test classes
  • target production classes
  • test data factories / setup helpers

2. Run the smallest useful test set first

Start narrow when debugging a failure; widen only after the fix is stable.

3. Analyze results

Focus on:

  • failing methods
  • exception types and stack traces
  • uncovered lines / weak coverage areas
  • whether failures indicate bad test data, brittle assertions, or broken production logic

4. Run a disciplined fix loop

When the issue is code or test quality:

  • delegate code fixes to platform-apex-generate skill when needed
  • add or improve tests
  • rerun focused tests before broader regression

5. Improve coverage intentionally

Cover:

  • positive path
  • negative / exception path
  • bulk path (251+ records where appropriate)
  • callout or async path when relevant

High-Signal Rules

Rule Rationale
Default to SeeAllData=false Ensures test isolation; prevents reliance on org-specific data
Every test must assert meaningful outcomes Tests with no assertions prove nothing and give false confidence
Test bulk behavior with 251+ records Triggers process in batches of 200; 251 records crosses the boundary
Use factories / @TestSetup when they improve clarity Consistent data creation in one place; rolled back between test methods
Pair Test.startTest() with Test.stopTest() for async Ensures async operations (queueable, future) complete before assertions
Do not hide flaky org dependencies inside tests Prevents intermittent failures tied to org state

Gotchas

Issue Resolution
Test passes locally but fails in CI org Check for SeeAllData=true or undeclared dependencies on org-specific records
Coverage drops unexpectedly after refactor Run focused class-level tests first, then widen to RunLocalTests to confirm
"Uncommitted work pending" error in callout test DML and HTTP callouts cannot be mixed in the same test context without Test.startTest() wrapping
Mock not taking effect in test Ensure Test.setMock() is called before the code that makes the callout
@TestSetup data missing in test method @TestSetup data is committed per test method — re-query it; do not store in static variables
API version 67.0 and higher without necessary access level checks Check failing SOQL/DML stack traces for CRUD/FLS access errors, using System.runAs with an assigned permission set when user-mode behavior is intended, or documenting a justified SYSTEM_MODE path when system access is required

Output Format

When finishing, report in this order:

  1. What tests were run
  2. Pass/fail summary
  3. Coverage result
  4. Root-cause findings
  5. Fix or next-run recommendation

Suggested shape:

Test run: <scope>
Org: <alias>
Result: <passed / partial / failed>
Coverage: <percent / key classes>
Issues: <highest-signal failures>
Next step: <fix class, add test, rerun scope, or widen regression>

Cross-Skill Integration

Need Delegate to Reason
Fix production code or author test classes platform-apex-generate skill Code generation and repair
Create bulk / edge-case test data platform-data-manage Realistic test datasets
Deploy updated tests to org platform-metadata-deploy Deployment workflows
Inspect detailed runtime logs platform-apex-logs-debug Deeper failure analysis

Reference File Index

File When to read
references/cli-commands.md All sf apex run test command flags, output formats, async execution, and coverage commands
references/test-patterns.md Test class templates — basic, bulk (251+), mock callout, and data factory patterns
references/testing-best-practices.md Core testing principles — AAA pattern, naming conventions, bulk, negative, and mock strategies
references/test-fix-loop.md Agentic test-fix loop implementation and failure analysis decision tree
references/mocking-patterns.md HttpCalloutMock, DML mocking, StubProvider, and selector mocking patterns
references/performance-optimization.md Techniques to reduce test execution time — DML mocking, SOQL mocking, loop optimizations
assets/basic-test.cls Template: standard test class with @TestSetup, positive / negative / bulk / edge-case methods
assets/bulk-test.cls Template: bulk test with 251+ records that crosses the 200-record trigger batch boundary
assets/mock-callout-test.cls Template: HTTP callout mock using HttpCalloutMock
assets/test-data-factory.cls Template: reusable TestDataFactory with create and insert helpers
assets/dml-mock.cls Template: IDML interface + DMLMock implementation for database-free unit tests
assets/stub-provider-example.cls Template: StubProvider-based dependency injection stub
scripts/parse-test-results.py Post-tool hook — parses sf apex run test JSON output and formats failures for the auto-fix loop

Score Guide

Score Meaning
108+ strong production-grade test confidence
96–107 good test suite with minor gaps
84–95 acceptable but strengthen coverage / assertions
< 84 below standard; revise before relying on it

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。