0
0
Testing Fundamentalstesting~15 mins

Performance test types (load, stress, spike, soak) in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify system behavior under different performance test types
Preconditions (2)
Step 1: Run a load test by simulating 1000 users accessing the system steadily for 30 minutes
Step 2: Observe system response times and error rates during load test
Step 3: Run a stress test by gradually increasing users beyond 1000 until system fails or degrades
Step 4: Observe system behavior and recovery after stress test
Step 5: Run a spike test by suddenly increasing users from 100 to 2000 within 1 minute
Step 6: Observe system response and error rates during spike test
Step 7: Run a soak test by running 500 users continuously for 8 hours
Step 8: Observe system stability, memory usage, and error rates during soak test
✅ Expected Result: System maintains acceptable response times and error rates during load and soak tests; system fails gracefully and recovers after stress test; system handles sudden user spikes without crashing.
Automation Requirements - JMeter
Assertions Needed:
Response time is below threshold during load and soak tests
Error rate is below 1% during load and soak tests
System recovers after stress test failure
No crashes during spike test
Best Practices:
Use separate test plans for each test type
Use assertions to validate response times and error rates
Use listeners to monitor system metrics
Run tests in controlled environment to avoid external interference
Automated Solution
Testing Fundamentals
/* JMeter test plan XML snippet for load test example */

<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.5">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Performance Test Plan" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.serialize_threadgroups">false</stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Load Test Thread Group" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">1</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1000</stringProp>
        <stringProp name="ThreadGroup.ramp_time">60</stringProp>
        <longProp name="ThreadGroup.start_time">1696000000000</longProp>
        <longProp name="ThreadGroup.end_time">1696003600000</longProp>
        <boolProp name="ThreadGroup.scheduler">true</boolProp>
        <stringProp name="ThreadGroup.duration">1800</stringProp>
        <stringProp name="ThreadGroup.delay">0</stringProp>
      </ThreadGroup>
      <hashTree>
        <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" enabled="true">
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
            <collectionProp name="Arguments.arguments"/>
          </elementProp>
          <stringProp name="HTTPSampler.domain">example.com</stringProp>
          <stringProp name="HTTPSampler.port">80</stringProp>
          <stringProp name="HTTPSampler.protocol">http</stringProp>
          <stringProp name="HTTPSampler.path">/api/test</stringProp>
          <stringProp name="HTTPSampler.method">GET</stringProp>
          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
          <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
          <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
          <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
          <stringProp name="HTTPSampler.connect_timeout"></stringProp>
          <stringProp name="HTTPSampler.response_timeout"></stringProp>
        </HTTPSamplerProxy>
        <hashTree/>
        <ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response Time Assertion" enabled="true">
          <collectionProp name="Asserion.test_strings">
            <stringProp name="0">200</stringProp>
          </collectionProp>
          <stringProp name="Assertion.test_field">Assertion.response_code</stringProp>
          <boolProp name="Assertion.assume_success">false</boolProp>
          <intProp name="Assertion.test_type">2</intProp>
        </ResponseAssertion>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

This JMeter test plan defines a load test with 1000 users ramping up over 60 seconds and running for 30 minutes (1800 seconds). The HTTP Request sampler targets the example.com API endpoint. The Response Assertion checks that the HTTP response code is 200, indicating success.

Separate test plans should be created similarly for stress, spike, and soak tests with appropriate thread counts, ramp times, and durations.

Listeners and monitoring tools should be added in JMeter GUI to observe response times, error rates, and system metrics during test execution.

Common Mistakes - 4 Pitfalls
Using very high number of users without ramp-up time
Not adding assertions to check response codes or times
Running tests without monitoring system resources
Mixing different test types in one test plan
Bonus Challenge

Now add data-driven testing with 3 different API endpoints for the load test

Show Hint