Windsurf testing

Test Database Not Resetting Between Tests in Windsurf Project

Tests in your Windsurf-generated project fail intermittently because the database retains data from previous test runs. Tests that pass individually fail when run together, test order matters, and adding a new test breaks existing ones. The test suite is unreliable and developers lose confidence in the results.

Cascade generates tests that create database records but doesn't clean them up afterward. Test A inserts a user, Test B expects an empty users table, and Test B fails because Test A's user is still there. The problem gets worse as more tests are added, creating an increasingly tangled web of data dependencies.

The failures are often non-deterministic — they depend on which tests run first, whether a previous test run completed fully, and sometimes even on timing. This makes them extremely hard to debug.

Error Messages You Might See

Expected 1 row but found 5 Error: duplicate key value violates unique constraint Test passed individually but fails in suite Error: relation has dependent rows - cannot truncate Expected empty array but received [previous test data]
Expected 1 row but found 5Error: duplicate key value violates unique constraintTest passed individually but fails in suiteError: relation has dependent rows - cannot truncateExpected empty array but received [previous test data]

Common Causes

  • No afterEach cleanup — Tests create database records but don't have afterEach hooks to clean up created data
  • Shared database between test runs — Tests use the development database instead of a dedicated test database that gets reset
  • No transaction rollback — Tests don't wrap operations in transactions that get rolled back, so changes persist
  • Truncation order wrong — Tables with foreign keys must be truncated in the correct order, or truncation fails silently
  • Seed data conflicts — Database seeds run before tests and create data with fixed IDs that conflict with test-created records
  • Parallel tests sharing state — Tests running in parallel write to the same tables and interfere with each other

How to Fix It

  1. Use transactions with rollback — Wrap each test in a database transaction and roll it back in afterEach. This is the fastest and cleanest approach
  2. Add truncation in beforeEach — Truncate all tables before each test with TRUNCATE TABLE ... CASCADE (PostgreSQL) or DELETE FROM (SQLite)
  3. Use a dedicated test database — Configure a separate database for tests in .env.test. Never run tests against your development or production database
  4. Install a test cleanup library — Use libraries like pg-mem (in-memory PostgreSQL), or prisma's test utils that handle cleanup automatically
  5. Isolate parallel tests — If running tests in parallel, use separate schemas or databases per worker to prevent interference
  6. Reset sequences and IDs — After truncation, reset auto-increment sequences so tests don't depend on specific ID values

Real developers can help you.

Kingsley Omage Kingsley Omage Fullstack software engineer passionate about AI Agents, blockchain, LLMs. Stanislav Prigodich Stanislav Prigodich 15+ years building iOS and web apps at startups and enterprise companies. I want to use that experience to help builders ship real products - when something breaks, I'm here to fix it. legrab legrab I'll fill this later Prakash Prajapati Prakash Prajapati I’m a Senior Python Developer specializing in building secure, scalable, and highly available systems. I work primarily with Python, Django, FastAPI, Docker, PostgreSQL, and modern AI tooling such as PydanticAI, focusing on clean architecture, strong design principles, and reliable DevOps practices. I enjoy solving complex engineering problems and designing systems that are maintainable, resilient, and built to scale. David Olverson David Olverson Solo dev shipping production apps with AI-assisted development. I specialize in rescuing broken Lovable/Bolt/Cursor builds and taking them to production. 10+ apps shipped including SaaS CRMs, gaming platforms, real estate tools, and Discord bots. Stack: Next.js 16, TypeScript, Tailwind CSS, FastAPI, PostgreSQL, Prisma. I use Claude Code with 50+ custom skills for rapid delivery. Average turnaround: 2-4 weeks from broken prototype to production. Jacek Rozanski Jacek Rozanski Senior PHP/Symfony developer and DevOps engineer with 20+ years of professional experience, running opcode.pl (web development agency, est. 2004). Day job: I'm the sole backend developer at merketing company where I own and maintain 11 PHP/Symfony microservices on AWS (ECS Fargate, RDS, S3, CloudFront), handle the full CI/CD pipeline (Bitbucket Pipelines, Docker), and manage monitoring with Sentry and CloudWatch. These services handle high request volumes in production every month. What I bring to AI-built apps: - I audit and fix security issues (OWASP methodology), performance bottlenecks, and architectural problems in codebases generated by Cursor, Claude Code, Lovable, Bolt, and v0 - I refactor AI-generated prototypes into production-grade applications with proper error handling, testing, and clean architecture (SOLID, DDD, hexagonal architecture) - I set up the infrastructure AI tools don't touch: AWS hosting, CI/CD pipelines, automated deployments, database optimization, monitoring, and alerting - I integrate external services: payment providers, email systems, partner APIs, SSO/auth Tech stack: PHP 8.x, Symfony, React, Next.js, PostgreSQL, MySQL, Docker, AWS (ECS, RDS, S3, SQS/SNS, CloudFront), Terraform, Supabase. I also use AI tools daily (Claude Code, Cursor) in my own workflow, so I understand both the strengths and the gaps in AI-generated code. Based in Poland (CET timezone). Available for async work and calls during EU/US business hours. Matthew Butler Matthew Butler Systems Development Engineer @ Amazon Web Services Anthony Akpan Anthony Akpan Developer with 8 years of experience building softwares fro startups hanson1014 hanson1014 Full-stack developer experienced in fixing and deploying AI-generated apps from Lovable, Bolt.new, Cursor, and Replit. I specialize in debugging Supabase integration issues (auth flows, RLS policies, database connections), fixing broken deployments, resolving routing/blank screen problems, and cleaning up messy React/Vite codebases. I also build production apps with the Claude API and have shipped a Mac desktop dev tool (Nexterm from scratch. Based in Hong Kong, fast turnaround. Antriksh Narang Antriksh Narang 5 years+ Experienced Dev (Specially in Web Development), can help in python, javascript, react, next.js and full stack web dev technologies.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Should I use truncation or transaction rollback for test cleanup?

Transaction rollback is faster and cleaner — each test runs in a transaction that gets rolled back, leaving no trace. However, it doesn't work if your code commits transactions internally. Truncation is simpler but slower because it actually deletes and recreates data.

Why do my tests pass individually but fail together?

This is a classic sign of missing test isolation. One test creates data that another test doesn't expect. Add cleanup (truncation or rollback) in beforeEach or afterEach hooks so each test starts with a known database state.

Related Windsurf Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help