|
| 1 | +--- |
| 2 | +id: risk-profile-analysis |
| 3 | +title: Risk Profile Analysis |
| 4 | +sidebar_label: Risk Profile Analysis |
| 5 | +description: Discover Keploy's Risk Profile Analysis feature, which automatically classifies API test failures as High, Medium, or Low risk, helping you instantly distinguish between breaking changes and minor updates. |
| 6 | +tags: |
| 7 | + - risk-analysis |
| 8 | + - change-management |
| 9 | + - breaking-changes |
| 10 | +keywords: |
| 11 | + - risk analysis |
| 12 | + - breaking changes |
| 13 | + - High Risk |
| 14 | + - Medium Risk |
| 15 | + - Low Risk |
| 16 | + - Risk Categories |
| 17 | + - Schema Changed |
| 18 | + - Schema Broken |
| 19 | +--- |
| 20 | + |
| 21 | +When API contracts change, tests are expected to fail. However, not all failures are equal. A minor, backward-compatible change (like adding a new optional field) is very different from a major, breaking change (like removing a field or changing a data type). |
| 22 | + |
| 23 | +The **Risk Profile Analysis** feature addresses this by automatically categorizing each test failure based on its potential impact. It assigns a risk level of **High**, **Medium**, or **Low**, giving developers immediate insight into the severity and nature of API changes. This helps distinguish between intentional contract updates and unintentional bugs right from the test report. |
| 24 | + |
| 25 | +### Key Concepts |
| 26 | + |
| 27 | +When a test fails, it is now assigned a risk level: |
| 28 | + |
| 29 | +- **HIGH**: Indicates a likely breaking change to the API contract. This is the highest level of risk. |
| 30 | + |
| 31 | + - **Triggers**: Status code changes, `Content-Type` header changes, removing fields from a JSON body, or changing the data type of a field (e.g., string to number). |
| 32 | + |
| 33 | +- **MEDIUM**: Indicates a change that might affect consumers but is not a direct contract violation. |
| 34 | + |
| 35 | + - **Triggers**: Changes in header values (other than `Content-Type`), or changes to field values within a JSON body while new fields are also being added. |
| 36 | + |
| 37 | +- **LOW**: Indicates a backward-compatible, non-breaking change. |
| 38 | + - **Triggers**: Only adding new, optional fields to a JSON body. |
| 39 | + |
| 40 | +To provide more detail, failures are also assigned one or more categories: |
| 41 | + |
| 42 | +- `SCHEMA_BROKEN`: A breaking change occurred in the response body (field removed, type changed). |
| 43 | +- `SCHEMA_ADDED`: Only new fields were added to the response body. |
| 44 | +- `SCHEMA_UNCHANGED`: The response body schema is identical, but values within it have changed. |
| 45 | +- `STATUS_CODE_CHANGED`: The HTTP status code was different from the expected one. |
| 46 | +- `HEADER_CHANGED`: One or more headers were different. |
| 47 | + |
| 48 | +##### How Risk Profiling Works During Testing |
| 49 | + |
| 50 | +1. **Failure Detection**: Keploy runs tests as usual. When a response mismatch is detected, the new analysis logic is triggered. |
| 51 | +2. **Deep Comparison**: Keploy performs a detailed comparison of the expected versus actual responses: |
| 52 | + - **Status Code**: Checks for any mismatch. |
| 53 | + - **Headers**: Pays special attention to the `Content-Type` header. |
| 54 | + - **JSON Body**: Analyzes the _nature_ of the difference by comparing the structure of the expected and actual JSON payloads to identify added fields, removed fields, and data type changes. |
| 55 | +3. **Risk Assessment**: Based on the comparison, a `RiskLevel` and one or more `FailureCategory` tags are assigned to the test result. |
| 56 | +4. **Enhanced Reporting**: The test report (`test-run-*-report.yaml`) is updated to include these new details. The summary now includes counts for high, medium, and low-risk failures, and each individual failed test specifies its risk and category. |
| 57 | + |
| 58 | +**Example Test Report Snippet:** |
| 59 | + |
| 60 | +```yaml |
| 61 | +version: 2.0.0 |
| 62 | +name: test-set-0 |
| 63 | +status: FAILED |
| 64 | +success: 0 |
| 65 | +failure: 12 |
| 66 | +high-risk: 7 |
| 67 | +medium-risk: 4 |
| 68 | +low-risk: 1 |
| 69 | +total: 12 |
| 70 | +tests: |
| 71 | + - name: test-1 |
| 72 | + status: FAILED |
| 73 | + # ... other fields |
| 74 | + failure_info: |
| 75 | + risk: HIGH |
| 76 | + category: |
| 77 | + - SCHEMA_BROKEN |
| 78 | + - name: test-2 |
| 79 | + status: FAILED |
| 80 | + # ... other fields |
| 81 | + failure_info: |
| 82 | + risk: LOW |
| 83 | + category: |
| 84 | + - SCHEMA_ADDED |
| 85 | +``` |
0 commit comments