Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

test-priorities-matrix.md 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <!-- Powered by BMAD-CORE™ -->
  2. # Test Priorities Matrix
  3. Guide for prioritizing test scenarios based on risk, criticality, and business impact.
  4. ## Priority Levels
  5. ### P0 - Critical (Must Test)
  6. **Criteria:**
  7. - Revenue-impacting functionality
  8. - Security-critical paths
  9. - Data integrity operations
  10. - Regulatory compliance requirements
  11. - Previously broken functionality (regression prevention)
  12. **Examples:**
  13. - Payment processing
  14. - Authentication/authorization
  15. - User data creation/deletion
  16. - Financial calculations
  17. - GDPR/privacy compliance
  18. **Testing Requirements:**
  19. - Comprehensive coverage at all levels
  20. - Both happy and unhappy paths
  21. - Edge cases and error scenarios
  22. - Performance under load
  23. ### P1 - High (Should Test)
  24. **Criteria:**
  25. - Core user journeys
  26. - Frequently used features
  27. - Features with complex logic
  28. - Integration points between systems
  29. - Features affecting user experience
  30. **Examples:**
  31. - User registration flow
  32. - Search functionality
  33. - Data import/export
  34. - Notification systems
  35. - Dashboard displays
  36. **Testing Requirements:**
  37. - Primary happy paths required
  38. - Key error scenarios
  39. - Critical edge cases
  40. - Basic performance validation
  41. ### P2 - Medium (Nice to Test)
  42. **Criteria:**
  43. - Secondary features
  44. - Admin functionality
  45. - Reporting features
  46. - Configuration options
  47. - UI polish and aesthetics
  48. **Examples:**
  49. - Admin settings panels
  50. - Report generation
  51. - Theme customization
  52. - Help documentation
  53. - Analytics tracking
  54. **Testing Requirements:**
  55. - Happy path coverage
  56. - Basic error handling
  57. - Can defer edge cases
  58. ### P3 - Low (Test if Time Permits)
  59. **Criteria:**
  60. - Rarely used features
  61. - Nice-to-have functionality
  62. - Cosmetic issues
  63. - Non-critical optimizations
  64. **Examples:**
  65. - Advanced preferences
  66. - Legacy feature support
  67. - Experimental features
  68. - Debug utilities
  69. **Testing Requirements:**
  70. - Smoke tests only
  71. - Can rely on manual testing
  72. - Document known limitations
  73. ## Risk-Based Priority Adjustments
  74. ### Increase Priority When:
  75. - High user impact (affects >50% of users)
  76. - High financial impact (>$10K potential loss)
  77. - Security vulnerability potential
  78. - Compliance/legal requirements
  79. - Customer-reported issues
  80. - Complex implementation (>500 LOC)
  81. - Multiple system dependencies
  82. ### Decrease Priority When:
  83. - Feature flag protected
  84. - Gradual rollout planned
  85. - Strong monitoring in place
  86. - Easy rollback capability
  87. - Low usage metrics
  88. - Simple implementation
  89. - Well-isolated component
  90. ## Test Coverage by Priority
  91. | Priority | Unit Coverage | Integration Coverage | E2E Coverage |
  92. | -------- | ------------- | -------------------- | ------------------ |
  93. | P0 | >90% | >80% | All critical paths |
  94. | P1 | >80% | >60% | Main happy paths |
  95. | P2 | >60% | >40% | Smoke tests |
  96. | P3 | Best effort | Best effort | Manual only |
  97. ## Priority Assignment Rules
  98. 1. **Start with business impact** - What happens if this fails?
  99. 2. **Consider probability** - How likely is failure?
  100. 3. **Factor in detectability** - Would we know if it failed?
  101. 4. **Account for recoverability** - Can we fix it quickly?
  102. ## Priority Decision Tree
  103. ```
  104. Is it revenue-critical?
  105. ├─ YES → P0
  106. └─ NO → Does it affect core user journey?
  107. ├─ YES → Is it high-risk?
  108. │ ├─ YES → P0
  109. │ └─ NO → P1
  110. └─ NO → Is it frequently used?
  111. ├─ YES → P1
  112. └─ NO → Is it customer-facing?
  113. ├─ YES → P2
  114. └─ NO → P3
  115. ```
  116. ## Test Execution Order
  117. 1. Execute P0 tests first (fail fast on critical issues)
  118. 2. Execute P1 tests second (core functionality)
  119. 3. Execute P2 tests if time permits
  120. 4. P3 tests only in full regression cycles
  121. ## Continuous Adjustment
  122. Review and adjust priorities based on:
  123. - Production incident patterns
  124. - User feedback and complaints
  125. - Usage analytics
  126. - Test failure history
  127. - Business priority changes
  128. ---
  129. ## Automated Priority Classification
  130. ### Example: Priority Calculator (Risk-Based Automation)
  131. ```typescript
  132. // src/testing/priority-calculator.ts
  133. export type Priority = 'P0' | 'P1' | 'P2' | 'P3';
  134. export type PriorityFactors = {
  135. revenueImpact: 'critical' | 'high' | 'medium' | 'low' | 'none';
  136. userImpact: 'all' | 'majority' | 'some' | 'few' | 'minimal';
  137. securityRisk: boolean;
  138. complianceRequired: boolean;
  139. previousFailure: boolean;
  140. complexity: 'high' | 'medium' | 'low';
  141. usage: 'frequent' | 'regular' | 'occasional' | 'rare';
  142. };
  143. /**
  144. * Calculate test priority based on multiple factors
  145. * Mirrors the priority decision tree with objective criteria
  146. */
  147. export function calculatePriority(factors: PriorityFactors): Priority {
  148. const { revenueImpact, userImpact, securityRisk, complianceRequired, previousFailure, complexity, usage } = factors;
  149. // P0: Revenue-critical, security, or compliance
  150. if (revenueImpact === 'critical' || securityRisk || complianceRequired || (previousFailure && revenueImpact === 'high')) {
  151. return 'P0';
  152. }
  153. // P0: High revenue + high complexity + frequent usage
  154. if (revenueImpact === 'high' && complexity === 'high' && usage === 'frequent') {
  155. return 'P0';
  156. }
  157. // P1: Core user journey (majority impacted + frequent usage)
  158. if (userImpact === 'all' || userImpact === 'majority') {
  159. if (usage === 'frequent' || complexity === 'high') {
  160. return 'P1';
  161. }
  162. }
  163. // P1: High revenue OR high complexity with regular usage
  164. if ((revenueImpact === 'high' && usage === 'regular') || (complexity === 'high' && usage === 'frequent')) {
  165. return 'P1';
  166. }
  167. // P2: Secondary features (some impact, occasional usage)
  168. if (userImpact === 'some' || usage === 'occasional') {
  169. return 'P2';
  170. }
  171. // P3: Rarely used, low impact
  172. return 'P3';
  173. }
  174. /**
  175. * Generate priority justification (for audit trail)
  176. */
  177. export function justifyPriority(factors: PriorityFactors): string {
  178. const priority = calculatePriority(factors);
  179. const reasons: string[] = [];
  180. if (factors.revenueImpact === 'critical') reasons.push('critical revenue impact');
  181. if (factors.securityRisk) reasons.push('security-critical');
  182. if (factors.complianceRequired) reasons.push('compliance requirement');
  183. if (factors.previousFailure) reasons.push('regression prevention');
  184. if (factors.userImpact === 'all' || factors.userImpact === 'majority') {
  185. reasons.push(`impacts ${factors.userImpact} users`);
  186. }
  187. if (factors.complexity === 'high') reasons.push('high complexity');
  188. if (factors.usage === 'frequent') reasons.push('frequently used');
  189. return `${priority}: ${reasons.join(', ')}`;
  190. }
  191. /**
  192. * Example: Payment scenario priority calculation
  193. */
  194. const paymentScenario: PriorityFactors = {
  195. revenueImpact: 'critical',
  196. userImpact: 'all',
  197. securityRisk: true,
  198. complianceRequired: true,
  199. previousFailure: false,
  200. complexity: 'high',
  201. usage: 'frequent',
  202. };
  203. console.log(calculatePriority(paymentScenario)); // 'P0'
  204. console.log(justifyPriority(paymentScenario));
  205. // 'P0: critical revenue impact, security-critical, compliance requirement, impacts all users, high complexity, frequently used'
  206. ```
  207. ### Example: Test Suite Tagging Strategy
  208. ```typescript
  209. // tests/e2e/checkout.spec.ts
  210. import { test, expect } from '@playwright/test';
  211. // Tag tests with priority for selective execution
  212. test.describe('Checkout Flow', () => {
  213. test('valid payment completes successfully @p0 @smoke @revenue', async ({ page }) => {
  214. // P0: Revenue-critical happy path
  215. await page.goto('/checkout');
  216. await page.getByTestId('payment-method').selectOption('credit-card');
  217. await page.getByTestId('card-number').fill('4242424242424242');
  218. await page.getByRole('button', { name: 'Place Order' }).click();
  219. await expect(page.getByText('Order confirmed')).toBeVisible();
  220. });
  221. test('expired card shows user-friendly error @p1 @error-handling', async ({ page }) => {
  222. // P1: Core error scenario (frequent user impact)
  223. await page.goto('/checkout');
  224. await page.getByTestId('payment-method').selectOption('credit-card');
  225. await page.getByTestId('card-number').fill('4000000000000069'); // Test card: expired
  226. await page.getByRole('button', { name: 'Place Order' }).click();
  227. await expect(page.getByText('Card expired. Please use a different card.')).toBeVisible();
  228. });
  229. test('coupon code applies discount correctly @p2', async ({ page }) => {
  230. // P2: Secondary feature (nice-to-have)
  231. await page.goto('/checkout');
  232. await page.getByTestId('coupon-code').fill('SAVE10');
  233. await page.getByRole('button', { name: 'Apply' }).click();
  234. await expect(page.getByText('10% discount applied')).toBeVisible();
  235. });
  236. test('gift message formatting preserved @p3', async ({ page }) => {
  237. // P3: Cosmetic feature (rarely used)
  238. await page.goto('/checkout');
  239. await page.getByTestId('gift-message').fill('Happy Birthday!\n\nWith love.');
  240. await page.getByRole('button', { name: 'Place Order' }).click();
  241. // Message formatting preserved (linebreaks intact)
  242. await expect(page.getByTestId('order-summary')).toContainText('Happy Birthday!');
  243. });
  244. });
  245. ```
  246. **Run tests by priority:**
  247. ```bash
  248. # P0 only (smoke tests, 2-5 min)
  249. npx playwright test --grep @p0
  250. # P0 + P1 (core functionality, 10-15 min)
  251. npx playwright test --grep "@p0|@p1"
  252. # Full regression (all priorities, 30+ min)
  253. npx playwright test
  254. ```
  255. ---
  256. ## Integration with Risk Scoring
  257. Priority should align with risk score from `probability-impact.md`:
  258. | Risk Score | Typical Priority | Rationale |
  259. | ---------- | ---------------- | ------------------------------------------ |
  260. | 9 | P0 | Critical blocker (probability=3, impact=3) |
  261. | 6-8 | P0 or P1 | High risk (requires mitigation) |
  262. | 4-5 | P1 or P2 | Medium risk (monitor closely) |
  263. | 1-3 | P2 or P3 | Low risk (document and defer) |
  264. **Example**: Risk score 9 (checkout API failure) → P0 priority → comprehensive coverage required.
  265. ---
  266. ## Priority Checklist
  267. Before finalizing test priorities:
  268. - [ ] **Revenue impact assessed**: Payment, subscription, billing features → P0
  269. - [ ] **Security risks identified**: Auth, data exposure, injection attacks → P0
  270. - [ ] **Compliance requirements documented**: GDPR, PCI-DSS, SOC2 → P0
  271. - [ ] **User impact quantified**: >50% users → P0/P1, <10% → P2/P3
  272. - [ ] **Previous failures reviewed**: Regression prevention → increase priority
  273. - [ ] **Complexity evaluated**: >500 LOC or multiple dependencies → increase priority
  274. - [ ] **Usage metrics consulted**: Frequent use → P0/P1, rare use → P2/P3
  275. - [ ] **Monitoring coverage confirmed**: Strong monitoring → can decrease priority
  276. - [ ] **Rollback capability verified**: Easy rollback → can decrease priority
  277. - [ ] **Priorities tagged in tests**: @p0, @p1, @p2, @p3 for selective execution
  278. ## Integration Points
  279. - **Used in workflows**: `*automate` (priority-based test generation), `*test-design` (scenario prioritization), `*trace` (coverage validation by priority)
  280. - **Related fragments**: `risk-governance.md` (risk scoring), `probability-impact.md` (impact assessment), `selective-testing.md` (tag-based execution)
  281. - **Tools**: Playwright/Cypress grep for tag filtering, CI scripts for priority-based execution
  282. _Source: Risk-based testing practices, test prioritization strategies, production incident analysis_