logoalt Hacker News

mystifyingpoiyesterday at 7:29 PM1 replyview on HN

> Just make every test independent

That's easier said than done. Simple example: API that returns a count of all users in the database. The obvious correct implementation that will work would be just to `select count(*) from users`. But if some other test touches users table beforehand, it won't work. There is no uuid to latch onto here.


Replies

christophilusyesterday at 9:48 PM

That’s why you run each test in a transaction with proper isolation level, and don’t commit the transaction— roll it back when the test ends. No test ever interferes with another that way.

show 1 reply