#
Pre-run Script
Pre-run scripts are powerful JavaScript code snippets that execute before running a test or a set of tests. They play a crucial role in establishing the necessary conditions for testing scenarios, allowing for dynamic behavior, and pre-processing of test parameters and environments.
#
Purpose of Pre-Run Scripts
Pre-run scripts in Kusho serve several key functions that enhance the flexibility and effectiveness of API testing:
- Dynamic Variable Setting: Initialize and update variables that are essential for the test runs, ensuring each test has the most current data available.
- Environment Setup: Prepare the testing environment by setting up necessary configurations or cleaning up data from previous test runs.
- Conditional Logic: Implement sophisticated testing scenarios where different paths may be taken depending on the test configuration or external factors.
- Data Generation: Create test data on-the-fly, such as timestamps, unique identifiers, or random values for comprehensive testing.
- Test Suite Configuration: Set up parameters that will affect how the entire test suite is executed.
#
Execution Flow
In Kusho's platform, the execution of pre-run scripts follows a specific order:
- Single Run Execution: When running a single test, the pre-run script executes once before that specific test.
- Run All Execution: When using the "Run all" feature, the pre-run script executes once before the entire test suite begins.
This structure allows for efficient setup of test environments and variables, whether you're running individual tests or the entire suite.