# 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.

<iframe width="560" height="315" src="https://www.youtube.com/embed/L3QGDuBgyLs?si=JP_KVaW-MRRyGjlv" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

<br>

### Purpose of Pre-Run Scripts
Pre-run scripts in Kusho serve several key functions that enhance the flexibility and effectiveness of API testing:
1. **Dynamic Variable Setting**: Initialize and update variables that are essential for the test runs, ensuring each test has the most current data available.
2. **Environment Setup**: Prepare the testing environment by setting up necessary configurations or cleaning up data from previous test runs.
3. **Conditional Logic**: Implement sophisticated testing scenarios where different paths may be taken depending on the test configuration or external factors.
4. **Data Generation**: Create test data on-the-fly, such as timestamps, unique identifiers, or random values for comprehensive testing.
5. **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:
1. **Single Run Execution**: When running a single test, the pre-run script executes once before that specific test.
2. **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.
