OpenParable
Skip to content
← Back to skills

testing-strategy-enforcement

Testing & Quality

Test strategy governance, coverage enforcement (80% line, 70% branch), test pyramid adherence, and CI gate enforcement

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/Hack23/cia/blob/HEAD/.github/skills/testing-strategy-enforcement/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/testing-strategy-enforcement, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Testing Strategy Enforcement Skill

Purpose

This skill enforces the CIA platform's testing strategy, ensuring consistent coverage thresholds, proper test pyramid adherence, and CI/CD gate enforcement. It provides actionable guidance for maintaining test quality across all modules.

When to Use This Skill

Apply this skill when:

  • ✅ Writing tests for new features
  • ✅ Reviewing PRs for test adequacy
  • ✅ Configuring CI/CD test gates
  • ✅ Investigating test failures or flaky tests
  • ✅ Measuring and improving test coverage
  • ✅ Deciding test scope for a change
  • ✅ Refactoring existing test suites

Do NOT use for:

  • ❌ Security-specific testing (use secure-code-review)
  • ❌ Performance testing design (use performance analysis)
  • ❌ UI/UX validation (use playwright-ui-testing)

Coverage Requirements

Mandatory Thresholds

MetricMinimumTargetBlocking?
Line Coverage80%85%+Yes — CI gate
Branch Coverage70%75%+Yes — CI gate
New Code Coverage80%90%+Yes — SonarCloud
Mutation ScoreN/A60%+Advisory

JaCoCo Configuration

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>check</id>
            <goals><goal>check</goal></goals>
            <configuration>
                <rules>
                    <rule>
                        <element>BUNDLE</element>
                        <limits>
                            <limit>
                                <counter>LINE</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.80</minimum>
                            </limit>
                            <limit>
                                <counter>BRANCH</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.70</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

Test Pyramid

        ╱╲
       ╱  ╲        E2E Tests (Playwright/Selenium)
      ╱ 5% ╲       - Critical user workflows only
     ╱──────╲      - Login, navigation, key features
    ╱        ╲
   ╱  15-20%  ╲    Integration Tests (Spring Test + TestContainers)
  ╱            ╲   - Service layer, repository layer
 ╱──────────────╲  - External API integration
╱                ╲
╱    75-80%       ╲ Unit Tests (JUnit 5 + Mockito)
╱──────────────────╲- Business logic, utilities, models

Unit Tests (75-80% of total tests)

Framework: JUnit 5 + Mockito + AssertJ

What to Test:

  • Business logic in service classes
  • Data transformation and mapping
  • Validation logic
  • Utility methods
  • Exception handling paths
  • Edge cases and boundary conditions

Patterns:

@ExtendWith(MockitoExtension.class)
class PoliticianServiceTest {

    @Mock
    private PoliticianRepository repository;

    @InjectMocks
    private PoliticianServiceImpl service;

    @Test
    void shouldReturnPoliticianWhenFound() {
        // Given
        var politician = createTestPolitician();
        when(repository.findById("id-1")).thenReturn(Optional.of(politician));

        // When
        var result = service.findById("id-1");

        // Then
        assertThat(result).isPresent();
        assertThat(result.get().getName()).isEqualTo("Test Name");
        verify(repository).findById("id-1");
    }

    @Test
    void shouldThrowWhenPoliticianNotFound() {
        when(repository.findById(anyString())).thenReturn(Optional.empty());

        assertThatThrownBy(() -> service.getById("invalid"))
            .isInstanceOf(EntityNotFoundException.class);
    }
}

Integration Tests (15-20% of total tests)

Framework: Spring Test + TestContainers

What to Test:

  • Database repository operations
  • Spring Security filter chains
  • Service layer with real dependencies
  • External API client integration
  • Transaction boundaries

Patterns:

@SpringBootTest
@ActiveProfiles("test")
class PoliticianRepositoryIntegrationTest {

    @Autowired
    private PoliticianRepository repository;

    @Test
    void shouldPersistAndRetrievePolitician() {
        var politician = createTestPolitician();
        repository.save(politician);

        var found = repository.findById(politician.getId());
        assertThat(found).isPresent();
    }
}

E2E Tests (5% of total tests)

Framework: Playwright

What to Test:

  • Critical user workflows (login, navigation)
  • Key data visualization pages
  • Admin operations
  • Cross-browser compatibility

CI Gate Enforcement

Required CI Gates

GateToolThresholdStage
CompilationMavenZero errorsBuild
Unit TestsJUnit 5100% passTest
CoverageJaCoCo80% line, 70% branchTest
Code QualitySonarCloudQuality gate passAnalysis
Security ScanCodeQLZero critical/highSecurity
Dependency CheckOWASP DCCVSS < 7Security
Integration TestsSpring Test100% passIntegration

Gate Failure Response

CI Gate Failed
    │
    ├─→ Test Failure?
    │   ├─→ Is it a flaky test? → Fix flaky test, don't skip
    │   ├─→ Is it a real regression? → Fix the code
    │   └─→ Is the test outdated? → Update the test
    │
    ├─→ Coverage Below Threshold?
    │   ├─→ New code not tested? → Add tests for new code
    │   ├─→ Existing coverage dropped? → Add missing tests
    │   └─→ Threshold too aggressive? → Document exception
    │
    ├─→ Quality Gate Failed?
    │   ├─→ Critical issue? → Fix immediately
    │   ├─→ False positive? → Document suppression
    │   └─→ Technical debt? → Create backlog item
    │
    └─→ Security Scan Failed?
        ├─→ Real vulnerability? → Fix before merge
        └─→ False positive? → Add suppression with justification

Test Quality Guidelines

Test Naming Convention

methodUnderTest_condition_expectedResult

Example: findById_whenPoliticianExists_returnsPolitician

Test Anti-Patterns to Avoid

Anti-PatternProblemSolution
No assertionsTest passes vacuouslyAdd meaningful assertions
Testing implementationBrittle, breaks on refactorTest behavior, not implementation
Ignoring exceptionsHides failuresUse assertThrows or assertThatThrownBy
Shared mutable stateTests affect each otherIsolate test state
Excessive mockingTests don't verify real behaviorMock boundaries only
Flaky testsErode CI trustFix root cause, never @Ignore
Test per lineSlow, redundantTest per behavior

Coverage Exceptions

Coverage exceptions are permitted only when:

  1. Code is auto-generated (JPA metamodel, JAXB)
  2. Code is boilerplate (getters/setters on simple DTOs)
  3. Infrastructure code with no business logic

Exception Process:

<!-- JaCoCo exclusion in pom.xml -->
<configuration>
    <excludes>
        <exclude>**/model/*_.class</exclude>    <!-- JPA metamodel -->
        <exclude>**/generated/**</exclude>       <!-- Generated code -->
    </excludes>
</configuration>

Measuring Test Effectiveness

Reports and Dashboards

# Generate coverage report
mvn clean test jacoco:report

# View report
open target/site/jacoco/index.html

# Generate aggregate report for multi-module
mvn clean verify -pl . -am

Coverage Trend Monitoring

  • SonarCloud tracks coverage trends over time
  • Coverage must not decrease on any PR
  • Target steady improvement toward 85%+ line coverage

ISMS Alignment

Testing AreaISO 27001 ControlNIST CSF
Unit TestingA.8.29PR.IP-12
Integration TestingA.8.29PR.IP-12
Security TestingA.8.33DE.CM-8
Test DocumentationA.8.25PR.IP-12
CI/CD GatesA.8.31PR.IP-12

References