Integration tests fail their purpose when they mock the very boundary they exist to test. This setup generates the integration contract for a CRUD service against its real database layer: data round-trips verified end to end, transaction behavior tested explicitly (commits commit, rollbacks leave no debris), each test owning its setup and teardown — with failure scenarios that only exist at boundaries: constraint violations surfacing as the right errors, downstream timeouts mid-operation, partial failure leaving clean state, concurrent access to the same data.
How to use this resource
1
Point it at the boundary
The service plus its real database — the contract treats the seam as the subject, not an inconvenience.
2
Trust the transaction scenarios
Half-failed operations and rollback verification are the tests that pay for themselves in one incident.
3
Keep tests self-owning
Each test sets up and tears down its own data — the rule that keeps integration suites parallel-safe.
Why This Works
Boundary-as-subject framing stops the mock-everything reflex
Transaction scenarios test the failure modes mocked tests structurally cannot see
Setup/teardown ownership keeps the suite honest as it grows
Best for
Data-access layers whose unit tests mock away the truth
Services where transaction boundaries carry the correctness
Teams burned by "works with mocks, fails with Postgres"
Not for
Pure business logic — unit strategy with mocks is faster and sharper there
Full user journeys through the UI — that's the E2E Test Prompt
Use cases
Testing CRUD services against the real database layer
Verifying rollback actually rolls back — before production proves it doesn't
Catching constraint violations that surface as 500s instead of 400s
FAQ
Why generate integration tests against a real database instead of mocks?
The TEST STRATEGY treats the boundary as the subject, and mocking it away removes the very thing under test. The FAILURE SCENARIOS — constraint violations surfacing as the right application errors, a half-failed transaction leaving nothing partially committed, concurrent access to the same data — only exist against real components. Mocked tests structurally cannot see them.
What test framework does this prompt target and what does it enforce?
It targets xUnit and bakes in that framework's discipline. FRAMEWORK GUIDANCE requires [Theory] with [InlineData]/[MemberData] for parametrized cases, constructor/IDisposable for setup since xUnit makes a new instance per test, async tests returning async Task never async void, and precise asserts like Assert.NotNull. You run the generated file and review it.
Where does the prompt put behaviors it couldn't test from the code I pasted?
They land in two explicit lists after the tests. The ASSUMPTIONS heading collects every assumption made about unspecified behavior, and GAPS lists behaviors that couldn't be tested with the information given. Where intent is ambiguous, the prompt tests the most likely intent and flags the ambiguity rather than weakening an assertion to make a test pass.
"Fix this error" gets guesses. The investigation contract gets a ten-stage diagnosis: facts separated from assumptions, alternatives weighed, fixes justified.
The JSON won't parse and you can't see why. Deterministic cause-sniffing — trailing commas, single quotes, unclosed brackets — and the repair prompt that fixes it.
Build a test suite that fails for real reasons, not green decoration — coverage across unit, integration, and edge cases, then a review for the gaps.
5 steps·30–60 minutes
Tip: Save time by exploring related resources and tools that integrate with this resource.
Feedback
Send feedback to NewPrompt
Found a bug, have a suggestion, or want to report something confusing? Send a short note.
Cookie preferences
NewPrompt uses optional Google Analytics cookies to understand site usage and improve the tools.
The site works normally if you decline analytics cookies.
Read more in our Cookie Policy.