> For the complete documentation index, see [llms.txt](https://docs.optimumsec.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.optimumsec.xyz/ongoing-upgrades/prevent-regression-bugs.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
