← Back to context

Comment by jakjak123

12 days ago

TestContainers, or just assume there is a postgres running locally.

> - maintain this, eg have good, representative testing data lying around?

This can be tricky, but usually my advice is to never even being trying to do write seed data in the database unless its very static. It just gets annoying to maintain and will often break. Try to work out a clean way to setup state in your tests using code, and do not rely on magic auto increment ids. Some of the more effective ways I have found is to f.ex. have every test create a fresh customer, then the test does work on that customer. Avoid tests assuming that the first object you create will get id == 1, makes it very annoying to maintain.

This is a big one. A term of art for this is "General Fixture", and for xUnit type testing I consider it to be an anti-pattern.

There's times when a big test fixture can provide value, but it's very context dependent and almost never for smaller/micro tests.