home / skills / proffesor-for-testing / agentic-qe / shift-left-testing

shift-left-testing skill

/v3/assets/skills/shift-left-testing

This skill helps you shift testing left by validating requirements, generating tests, and automating CI checks to catch defects early.

npx playbooks add skill proffesor-for-testing/agentic-qe --skill shift-left-testing

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
6.0 KB
---
name: shift-left-testing
description: "Move testing activities earlier in the development lifecycle to catch defects when they're cheapest to fix. Use when implementing TDD, CI/CD, or early quality practices."
category: testing-methodologies
priority: high
tokenEstimate: 900
agents: [qe-test-generator, qe-requirements-validator, qe-regression-risk-analyzer]
implementation_status: optimized
optimization_version: 1.0
last_optimized: 2025-12-02
dependencies: []
quick_reference_card: true
tags: [shift-left, early-testing, tdd, bdd, ci-cd, prevention]
---

# Shift-Left Testing

<default_to_action>
When implementing early testing practices:
1. VALIDATE requirements before coding (testability, BDD scenarios)
2. WRITE tests before implementation (TDD red-green-refactor)
3. AUTOMATE in CI pipeline (every commit triggers tests)
4. FOLLOW test pyramid: Many unit (70%), some integration (20%), few E2E (10%)
5. FIX defects immediately - never let them accumulate

**Quick Shift-Left Levels:**
- Level 1: Unit tests with each PR (developer responsibility)
- Level 2: TDD practice (tests before code)
- Level 3: BDD/Example mapping in refinement (requirements testing)
- Level 4: Risk analysis in design (architecture testing)

**Critical Success Factors:**
- Defects found in requirements cost 1x; in production cost 100x
- Every commit must run automated tests
- Quality is built in, not tested in
</default_to_action>

## Quick Reference Card

### When to Use
- Reducing cost of defects
- Implementing CI/CD pipelines
- Starting TDD practice
- Improving requirements quality

### Cost of Defects by Phase
| Phase | Relative Cost | Example |
|-------|--------------|---------|
| Requirements | 1x | Fix doc: 30 min |
| Design | 5x | Redesign: few hours |
| Development | 10x | Code fix: 1 day |
| Testing | 20x | Fix + retest: 2 days |
| Production | 100x | Hotfix + rollback + investigation |

### Test Pyramid
```
       /\        E2E (10%) - Critical user journeys
      /  \
     /    \      Integration (20%) - Component interactions
    /      \
   /________\    Unit (70%) - Fast, isolated, comprehensive
```

### Shift-Left Levels
| Level | Practice | When |
|-------|----------|------|
| 1 | Unit tests in PR | Before merge |
| 2 | TDD | Before implementation |
| 3 | BDD/Example Mapping | During refinement |
| 4 | Risk Analysis | During design |

---

## Level 1: Tests in Every PR

```yaml
# CI pipeline - tests run on every commit
name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run test:unit
      - run: npm run test:integration
      - run: npm run lint

  quality-gate:
    needs: test
    steps:
      - name: Coverage Check
        run: npx coverage-check --min 80
      - name: No New Warnings
        run: npm run lint -- --max-warnings 0
```

---

## Level 2: TDD Practice

```javascript
// Red: Write failing test first
test('calculates discount for orders over $100', () => {
  const order = new Order([{ price: 150 }]);
  expect(order.discount).toBe(15); // 10% off
});

// Green: Minimal implementation
class Order {
  get discount() {
    return this.total > 100 ? this.total * 0.1 : 0;
  }
}

// Refactor: Improve while keeping green
```

---

## Level 3: BDD in Refinement

```gherkin
# Example mapping before coding
Feature: Loyalty Discount
  Scenario: Gold member gets 15% discount
    Given a customer with "gold" membership
    When they checkout with $200 in cart
    Then discount applied is $30
    And order total is $170

  Scenario: New customer gets no discount
    Given a customer with no membership
    When they checkout with $200 in cart
    Then no discount is applied
```

---

## Level 4: Risk Analysis in Design

```typescript
// During architecture review
await Task("Risk Analysis", {
  phase: 'design',
  component: 'payment-service',
  questions: [
    'What happens when payment gateway times out?',
    'How do we handle duplicate submissions?',
    'What if inventory changed during checkout?'
  ]
}, "qe-requirements-validator");

// Output: Testability requirements, failure mode tests
```

---

## Agent-Assisted Shift-Left

```typescript
// Validate requirements testability
await Task("Requirements Validation", {
  requirements: userStories,
  check: ['INVEST-criteria', 'testability', 'ambiguity'],
  generateBDD: true
}, "qe-requirements-validator");

// Generate tests from requirements
await Task("Generate Tests", {
  source: 'requirements',
  types: ['unit', 'integration', 'e2e'],
  coverage: 'comprehensive'
}, "qe-test-generator");

// Smart test selection for changes
await Task("Select Regression Tests", {
  changedFiles: prFiles,
  algorithm: 'risk-based',
  targetReduction: 0.7  // 70% time savings
}, "qe-regression-risk-analyzer");
```

---

## Agent Coordination Hints

### Memory Namespace
```
aqe/shift-left/
├── requirements/*       - Validated requirements
├── generated-tests/*    - Auto-generated tests
├── coverage-targets/*   - Coverage goals by component
└── pipeline-results/*   - CI/CD test history
```

### Fleet Coordination
```typescript
const shiftLeftFleet = await FleetManager.coordinate({
  strategy: 'shift-left',
  agents: [
    'qe-requirements-validator',     // Level 3-4
    'qe-test-generator',             // Level 2
    'qe-regression-risk-analyzer'    // Smart selection
  ],
  topology: 'sequential'
});
```

---

## Related Skills
- [tdd-london-chicago](../tdd-london-chicago/) - TDD practices
- [holistic-testing-pact](../holistic-testing-pact/) - Proactive testing
- [cicd-pipeline-qe-orchestrator](../cicd-pipeline-qe-orchestrator/) - Pipeline integration
- [shift-right-testing](../shift-right-testing/) - Production feedback

---

## Remember

**Earlier = Cheaper.** Requirements defects cost 1x; production defects cost 100x. Test pyramid: 70% unit, 20% integration, 10% E2E. Every commit runs tests. TDD builds quality in.

**With Agents:** Agents validate requirements testability, generate tests from specs, and select optimal regression suites. Use agents to implement shift-left practices consistently.

Overview

This skill moves testing activities earlier in the development lifecycle so defects are caught when they are cheapest to fix. It embeds testability into requirements, promotes TDD/BDD practices, and automates tests in CI so every commit exercises quality checks. The goal is to reduce defect cost, shorten feedback loops, and keep quality built in rather than bolted on.

How this skill works

The skill validates requirements for testability, generates tests from specifications, and wires tests into CI pipelines to run on every commit. It supports levels from unit tests per PR to risk-driven design testing, and coordinates agents to produce BDD scenarios, unit/integration/E2E tests, and smart regression selection. Outputs include validated requirements, generated test artifacts, coverage targets, and pipeline results stored in a predictable memory namespace.

When to use it

  • Adopting TDD or starting TDD practice across the team
  • Implementing or improving CI/CD pipelines to run tests per commit
  • Reducing the cost of defects by shifting work left in the SDLC
  • Improving requirements clarity and testability during refinement
  • Introducing risk analysis during design to generate failure-mode tests

Best practices

  • Validate requirements for testability and remove ambiguity before coding
  • Write failing tests first (TDD): red → green → refactor
  • Follow the test pyramid: ~70% unit, 20% integration, 10% E2E
  • Automate tests to run on every commit and gate merges with quality checks
  • Fix defects immediately; do not allow backlog accumulation

Example use cases

  • Run requirements validation agent during backlog refinement to generate BDD scenarios and acceptance tests
  • Enforce unit and integration tests in CI for every PR with coverage and lint gates
  • Use agent-generated tests to bootstrap TDD on legacy modules before refactoring
  • Apply risk-based test selection to shrink regression suites after a large change
  • Integrate design-phase risk analysis to produce failure-mode tests for critical services

FAQ

How does this skill reduce cost of defects?

By catching defects earlier—during requirements, design, or development—issues are fixed with far less effort than when found in production.

What types of tests does it generate?

It generates unit, integration, and E2E tests and can produce BDD scenarios from requirements; it also supports smart regression selection to prioritize tests by risk.