This visual execution shows how to set up and tear down a test database connection in Express tests. First, beforeAll hook runs and connects to the test database, changing the DB connection state from disconnected to connected. Then tests run using this connection. After all tests finish, afterAll hook disconnects the test database, returning the connection state to disconnected. This ensures tests have a live DB connection and that resources are freed after tests. Forgetting to disconnect can cause the test suite to hang or leak resources. The execution table tracks each step, showing actions, async operations, and connection states. The variable tracker highlights how the DB connection state changes over time. This pattern keeps tests reliable and clean.