Performance: Test database setup and teardown
MEDIUM IMPACT
This affects the speed and reliability of test execution, impacting developer feedback time and CI pipeline efficiency.
beforeAll(async () => { await db.connect(); await db.createCollections(); await db.seedTestData(); }); afterAll(async () => { await db.dropDatabase(); await db.disconnect(); }); beforeEach(async () => { await db.clearCollections(); });
beforeEach(async () => { await db.dropDatabase(); await db.createCollections(); await db.seedTestData(); }); afterEach(async () => { await db.dropDatabase(); });
| Pattern | DB Operations | Test Runtime Impact | Resource Usage | Verdict |
|---|---|---|---|---|
| Drop and recreate DB per test | High (drop + create each test) | Very slow (seconds per test) | High (many DB calls) | [X] Bad |
| Setup once, clear data per test | Moderate (clear collections only) | Fast (milliseconds per test) | Low (fewer DB calls) | [OK] Good |