Hacker News new | past | comments | ask | show | jobs | submit login

I think it's a generally accepted rule rather than a hard and fast one. That's because a unit test is usually expected to run faster than other test types, and they're expected to be the most deterministic. Using an actual database for a unit test not only can slow things down because of setup, but it can cause state leakage(which may not be a problem for the app itself) between tests and introduces more possibilities for race conditions and random test failures since it relies on a separate process.

But I see no reason why a unit test has to be databaseless. Of course you can write a unit test that uses a database! If it makes sense to do it, then do it. There's no computer god dictating rules to us that we are not allowed to break. However, it probably doesn't make sense to do so. ;)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: