Skip to content

Mathematical validation in hurl github #4499

@azoz-w

Description

@azoz-w

Problem to solve

Currently, Hurl does not support mathematical operations in assertions. Users need to manually calculate expected values or use multiple variables, which makes tests less maintainable and harder to read, especially for API responses involving calculations like loan repayments, pricing, taxes, or any computed totals.

For example, if testing a loan API that returns totalRepayment, tenure, and installment, there's no way to directly assert that totalRepayment == tenure * installment within Hurl.

Proposal

Add support for mathematical expressions in Hurl assertions, allowing arithmetic operations (+, -, *, /, %, ^) between:

  • JSON response values (using JSONPath)
  • Variables (using {{variable}} syntax)
  • Literal numbers

Example syntax:

POST https://api.example.com/loan/calculate
{
  "amount": 10000,
  "tenure": 12,
  "rate": 5
}

HTTP 200
[Asserts]
$.totalRepayment == {{tenure}} * {{installment}}
$.totalInterest == {{tenure}} * {{installment}} - {{principal}}
$.monthlyPayment == ({{amount}} * {{rate}}) / 100

Alternative syntax (if above is too complex):

[Asserts]
$.totalRepayment == eval "{{tenure}} * {{installment}}"

The feature should support:

  • Basic arithmetic operators: +, -, *, /, % (modulo), ^ (power)
  • Parentheses for operation precedence
  • Mixed operands (JSONPath values, variables, literals)
  • Standard order of operations (PEMDAS/BODMAS)

Additional context and resources

Use cases:

  1. Financial APIs: Validating loan calculations, tax computations, pricing totals
  2. E-commerce: Asserting total == subtotal + tax + shipping
  3. Analytics APIs: Verifying percentage calculations or aggregated metrics
  4. Any computed values: Reducing test brittleness by expressing relationships rather than hard-coded values

Current workaround:
Users must either:

  • Pre-calculate values and store in variables (requires external scripting)
  • Skip validation of mathematical relationships entirely

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions