Guides

Assertions

Assertions

Introduction

Assertions are essential elements in testing scenarios. They allow you to verify the expected behavior of your system under test, ensuring that it meets predefined criteria. In this guide, we'll delve into the add_assert_v1 function and how it facilitates the incorporation of assertions into your test scenarios.

add_assert_v1 Function

The add_assert_v1 function is designed to add assertions to your test scenarios. It enables you to specify various parameters to customize the assertion process according to your testing requirements.

Parameters

  1. assert_value: The name of the value to assert.

  2. assert_expected_value: The expected value for the assertion.

  3. assert_unexpected_value: The unexpected value for the assertion (optional).

  4. assert_step: The assert step (optional).

  5. max_retries: The maximum number of retries for the assertion (optional).

  6. interval: The interval between retries (optional).

  7. until: The condition to stop retrying (optional).

  8. assert_step_name: Assert step name used by the code generation to support assert override (optional).

  9. description: A description of the assert step (optional).

  10. ignore: If set, a failure will not break out of the scenario (optional).

  11. break_: If set, will break out of the test after the assert (for debugging) (optional).

  12. if_: Condition for executing this assert (optional).

Usage Example

Here's an example demonstrating how to use the add_assert_v1 function to assert the status code of a specific request:

# Endpoint /v1/artists and Method POST
scenario.add_request_v1(
    request=artists_POST_request,
    step_name="artists_functional_scenario-0",
    vars_override={},
    description="Endpoint /v1/artists and Method POST"
)

# Assert of scenario step artists_functional_scenario-0 - Endpoint /v1/artists and Method POST
scenario.add_assert_v1(
    assert_value="requests.artists_POST.code",
    assert_expected_value="201", 
    assert_step_name="artists_functional_scenario-1",
    description="Assert of scenario step artists_functional_scenario-0 - Endpoint /v1/artists and Method POST"
)

In this example:

  • We first add a request to the scenario, specifying the endpoint /v1/artists and the HTTP method POST.

  • Next, we add an assertion using add_assert_v1. Here, we assert that the status code of the artists_POST request is 201.

  • The assert_value parameter specifies the value to assert, which in this case is the status code of the artists_POST request.

  • We set the assert_expected_value parameter to "201" to indicate that we expect the status code to be 201.

  • Other optional parameters such as assert_step_name and description provide additional context for the assertion.

The add_assert_v1 function empowers testers to incorporate assertions seamlessly into their test scenarios, enabling thorough validation of system behavior. By leveraging this function with appropriate parameters, testers can ensure the reliability and robustness of their testing processes.

© 2024 Skyramp, Inc. All rights reserved.

© 2024 Skyramp, Inc. All rights reserved.

© 2024 Skyramp, Inc. All rights reserved.