top of page

Randomized Coverage Selections

  • Writer: Elisha Antunes
    Elisha Antunes
  • Jun 8
  • 2 min read

Updated: Jun 23

Coverage selections during quoting are typically driven by risk, budget, and industry standards—not by randomness. But as testers, we still aim to simulate varied and realistic combinations across many API calls.


To reflect this, I built a pre-request script in Postman that:

  • Always includes required coverages

  • Randomly selects optional coverages (1–2 per submission)

  • Dynamically adds conditional coverages based on answers to application questions


More information on the coverage rules and logic are found in my Freelance API project.


Coverage Categories

Type

Examples

Behavior in Script

Required

professionalLiability, generalLiability

Always included

Optional

cyberLiability, waiverOfSubrogation, primaryNonContributory

Randomly included (1–2)

Conditional

rentedEquipment

Included only if application answers require it


Step 1: Define Coverages

const requiredCoverages = [
  { name: "professionalLiability", amount: pickRandom(['1000000', '2000000', '3000000']) },
  { name: "generalLiability", amount: pickRandom(['1000000', '2000000', '3000000']) }
];

const optionalCoverages = [
  { name: "cyberLiability", amount: pickRandom(['2000000', '3000000', '4000000']) },
  { name: "primaryNonContributory", value: pickRandom(["included", "excluded"]) },
  { name: "waiverOfSubrogation", value: pickRandom(["included", "excluded"]) }
];


Step 2: Simulate Conditional Logic

The rentedEquipment coverage is only required when the application answer to "equipmentRental" is "Yes".

const conditionalCoverages = [
  { name: "rentedEquipment", amount: pickRandom(['10000', '15000', '25000']) }
];

const rentalAnswer = applicationQuestions.find(q => q.description === "equipmentRental")?.value;
if (rentalAnswer === 'Yes') {
  coverages.push(conditionalCoverages[0]);
}

This logic mirrors how underwriting decisions work: coverage isn’t just based on product type—it’s conditional on risk factors.


Step 3: Randomize Optional Coverage Selection

const selectedOptional = optionalCoverages.sort(() => 0.5 - Math.random()).slice(0, 2);
const finalCoverages = requiredCoverages.concat(selectedOptional, coverages);
pm.collectionVariables.set("coverages", JSON.stringify(finalCoverages));

This ensures:

  • You never include all optional coverages (over-insured)

  • You always simulate a decision being made by the user

  • The test suite runs with variety—but predictably valid logic


Validation Example (Optional Post-Request Script)

If you want to enforce certain rules in the post-request test, try something like:

const hasRentedEquipment = finalCoverages.some(c => c.name === 'rentedEquipment');
if (rentalAnswer === 'Yes') {
  pm.test("Rented Equipment coverage should be present", function () {
    pm.expect(hasRentedEquipment).to.be.true;
  });
}

Why This Matters

  • Simulates human decision-making

  • Ensures compliance with conditional underwriting logic

  • Increases test variability without breaking business rules


This ensures we are mimicking real user behavior with just enough variability to validate the system handles it all.

Recent Posts

See All
Link Matching

When testing APIs that model real-world relationships, it’s not enough to check individual fields — you often need to validate how...

 
 
bottom of page