Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 16, 2025

This PR enhances the swagger-coverage-cli tool with comprehensive negative testing coverage analysis, transforming it from a basic API coverage tool into a complete QA analysis platform that follows industry best practices for API testing.

Problem Statement

The original tool only measured positive test coverage (successful API responses), missing a critical aspect of quality assurance: negative testing. According to QA best practices, robust API testing should include:

  • Error scenario testing (4xx/5xx status codes)
  • Boundary value analysis
  • Invalid input validation
  • Security and authorization testing
  • Performance and rate limiting scenarios

Solution Overview

🧪 Enhanced Negative Testing Framework

1. Comprehensive Error Status Code Testing

# Before: Only 2xx status codes
responses:
  '200':
    description: Success

# After: Complete error scenario coverage  
responses:
  '200':
    description: Success
  '400':
    description: Bad request - invalid parameters
  '401': 
    description: Unauthorized - authentication required
  '403':
    description: Forbidden - insufficient permissions
  '404':
    description: Resource not found
  '409':
    description: Conflict - resource version mismatch
  '422':
    description: Validation errors

2. Advanced Test Pattern Analysis

  • Boundary Value Testing: Parameter limits, string lengths, numeric ranges
  • Invalid Input Testing: Malformed JSON, wrong content types, enum violations
  • Security Testing: Authentication failures, authorization checks
  • Unsupported Operations: Invalid HTTP methods, non-existent endpoints

3. Quality Metrics & Scoring

=== Negative Testing Analysis ===
Positive Test Coverage: 100.0% (5/5)
Negative Test Coverage: 92.9% (13/14)

Error Status Code Coverage:
 - 400: 80.0% (4/5)  
 - 401: 100.0% (1/1)
 - 403: 100.0% (1/1)
 - 404: 100.0% (2/2)
 - 409: 100.0% (2/2)
 - 422: 100.0% (2/2)

Negative Testing Quality Score: 83.1/100 (🏆 Excellent)

🎯 Enhanced HTML Report

The HTML report now includes a dedicated "Negative Testing Analysis" section with:

  • Visual Charts: Positive vs Negative testing distribution
  • Error Status Metrics: Coverage breakdown per HTTP status code
  • Quality Score Dashboard: 0-100 scoring with assessment levels
  • Smart Recommendations: Actionable suggestions for missing test patterns

Negative Testing Report

🚀 CLI Enhancement

New --negative-testing flag enables comprehensive analysis:

# Basic usage
swagger-coverage-cli api.yaml collection.json --negative-testing

# With Newman reports  
swagger-coverage-cli api.yaml newman-report.json --newman --negative-testing

Key Features

1. 20 New Test Scenarios

  • Error status code tests (400, 401, 403, 404, 409, 422, 429)
  • Boundary value tests (min/max limits, string lengths)
  • Invalid input tests (malformed JSON, wrong types)
  • Unsupported operation tests (invalid methods, endpoints)

2. Quality Assessment Framework

  • Error Coverage Score: Percentage of documented errors tested
  • Test Ratio Analysis: Optimal positive/negative test balance (70/30)
  • Quality Grades: 🏆 Excellent (80+), ✅ Good (60+), ⚠️ Fair (40+), ❌ Poor (<40)
  • Actionable Recommendations: Specific guidance for improvement

3. Multiple Input Support

  • Works with both Postman Collections and Newman Reports
  • Maintains backward compatibility with existing workflows
  • Enhanced analysis for actual execution data from Newman

4. Comprehensive Metrics

// Example quality calculation
const qualityScore = calculateQualityScore({
  errorStatusCoverage: 92.9,    // 60% weight
  positiveNegativeRatio: 73.7,  // 40% weight  
  boundaryTests: 9,
  invalidInputTests: 8,
  securityTests: 0
});
// Result: 83.1/100 (🏆 Excellent)

Impact

For QA Teams

  • Complete Test Coverage Analysis: Identifies gaps in both positive and negative testing
  • Industry Best Practices: Follows established QA methodologies for API testing
  • Actionable Insights: Specific recommendations for improving test quality

For Development Teams

  • Risk Assessment: Understand which error scenarios are untested
  • Quality Gates: Use quality scores for CI/CD pipeline decisions
  • Documentation: Visual reports for stakeholder communication

For DevOps Teams

  • CI/CD Integration: Automated quality scoring in pipelines
  • Trend Analysis: Track testing quality improvements over time
  • Multi-API Support: Analyze entire API portfolios

Testing

  • 103 tests passing (83 existing + 20 new negative testing scenarios)
  • New test file: negative-testing-coverage.test.js with comprehensive analysis
  • Enhanced fixtures: Updated API specs and collections with negative test cases
  • Backward compatibility: All existing functionality preserved

Breaking Changes

None. All changes are additive and backward compatible.

Usage Examples

Basic Analysis:

swagger-coverage-cli api.yaml tests.json --negative-testing

Advanced Analysis with Newman:

newman run collection.json --reporters json --reporter-json-export report.json
swagger-coverage-cli api.yaml report.json --newman --negative-testing

Multi-API Portfolio:

swagger-coverage-cli "api1.yaml,api2.yaml,api3.yaml" tests.json --negative-testing

This enhancement positions swagger-coverage-cli as a comprehensive API quality analysis tool that helps teams build more robust, well-tested APIs following industry QA best practices.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 16, 2025 17:35
…ment

Co-authored-by: dreamquality <130073078+dreamquality@users.noreply.github.com>
…ractices

Co-authored-by: dreamquality <130073078+dreamquality@users.noreply.github.com>
Copilot AI changed the title [WIP] update it to have negative testing coverage as well following best QA principles Implement comprehensive negative testing coverage analysis following QA best practices Sep 16, 2025
Copilot AI requested a review from dreamquality September 16, 2025 17:48
@dreamquality dreamquality added the invalid This doesn't seem right label Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants