# AsyncUnit vs PHPUnit

### Why not just use PHPUnit and the Amp wrapper?

If you're familiar with unit testing and Amp you've probably come across the [amphp/phpunit-util wrapper](https://github.com/amphp/phpunit-util). This is a great utility that really helps improve writing unit tests with PHPUnit and Amp. I highly recommend you check it out and use it! However, where the wrapper starts to have problems is with more complete integration testing that requires more exact control of the Loop... particularly those tests with database interactions.

The current architecture of PHPUnit and the Amp wrapper is one where each *test* gets its own Loop. For unit tests that are focused on ensuring a clean, known state this is likely the correct approach. However, if you need a resource with a heavy initialization cost, such as a connection to a database, that has to be run for every single test problems can quickly crop up. It would not take much to imagine a test suite attempting so many connections to the database in such a short time frame that the database becomes non-responsive! That's precisely the scenario that led to the creation of this framework and its design has been guided by the need to have a single Loop running all tests.

### Use both frameworks

In sufficiently complex applications you should probably be making use of *both* frameworks. Continue to use PHPUnit and the wrapper for your simple *unit* tests. It is mature and has a ton of support. When you start performing integration tests and you experience the pain of having your app server or database connection reset on every test start to incorporate AsyncUnit!

That being said, nothing is stopping you from using AsyncUnit as your testing framework for both unit and integration tests! However, that's not the goal of AsyncUnit and the framework was designed to solve a specific need instead of replacing your primary testing framework.


---

# 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.labrador-kennel.io/async-unit/asyncunit-vs-phpunit.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.
