Checklist of Best Practices for Writing Assertions

  October 11, 2019

Studies show us that a quarter of visitors abandon websites that take more than 4 seconds to load. They also show that nearly half of users don't revisit poorly performing websites. At the same time, Walmart found that every 1-second improvement in page load time improved conversion rates by 2%.

In other words, load tests are important. At least as important as unit and integration tests.

In load tests, assertions verify that a server returns an expected result. For example, a “duration assertion” tests if a response was received within a specified time. Responses that take longer than the threshold "fail" since they don't meet performance specifications.

Read more about different types of assertion and the best use of assertions in your load test.

Use this checklist to help you write strong assertions in your tests.

  • Tie Assertions to Business Objectives
    Assertions should be representative of business objectives — not abstract requirements pulled out of thin air.
     
  • Identify the Right KPIs to Measure in Assertions
    Response times may be the most popular KPI for load tests, but it’s equally important to look at other metrics important to your business.
     
  • Try to Mimic Real Behaviors in Load Tests
    Use realistic timings when creating load tests before making assertions in order to ensure that load test conditions mimic actual users.
     
  • Create Test Cases Before Creating Tests
    Carefully plan out test inputs, execution conditions and expected outputs before scripting or recording a load test and writing assertions.
     
  • Parameterize Values for Realistic Conditions
    Parameterize load test values and create assertions that account for realistic conditions rather than only testing one possible outcome.
     

Double Check Everything Before Running a Test
Load tests can be resource intensive, so it’s important to do a test run before running the test across thousands or tens of thousands of virtual users.

Start your free 14-day LoadNinja trial today.