# Use Existing Unit Tests to Prevent Regression Bugs

When upgrading or modifying smart contracts, regression bugs—where previously working functionality breaks—can easily occur. Utilizing existing unit tests effectively is one of the best ways to ensure that your upgrades do not inadvertently disrupt functionality.

***

## Steps to Reuse Unit Tests

### 1. **Organize Existing Tests**

* Ensure all unit tests from the original contract are clearly documented and accessible.
* Separate tests into categories, such as critical paths (e.g., token transfers) and auxiliary features (e.g., metadata retrieval).

### 2. **Run Tests Against the Upgraded Contract**

* Execute all existing unit tests on the upgraded contract in a testing environment.
* Compare results with the original contract’s test results to confirm consistency.

### 3. **Address Failures Immediately**

* Investigate any failing tests to determine if the issue is due to:
  * A bug in the upgraded contract.
  * Intentional changes in behavior that require test updates.

### 4. **Expand Test Coverage**

* Add new unit tests to cover newly introduced features in the upgraded contract.
* Ensure the new tests integrate seamlessly with the existing suite.

### 5. **Integrate Regression Testing into CI/CD**

* Automate the execution of unit tests in your Continuous Integration/Continuous Deployment (CI/CD) pipeline.
* Require all tests to pass before allowing the upgrade to proceed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.optimumsec.xyz/ongoing-upgrades/prevent-regression-bugs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
