2 ms·
> You will never switch databases We used SQLAlchemy on a Python project which allowed us to use an in-memory SQLite DB in our integration tests. This gave us
by damagednoob 4y ago
> You will never switch databases
We used SQLAlchemy on a Python project which allowed us to use an in-memory SQLite DB in our integration tests. This gave us blazingly fast database tests during development where a database was torn down and recreated, with data, for each test in milliseconds. When the commits were pushed, CI would run the tests against SQLite and MySql.
It worked extremely well and would be a tremendous amount of effort to handwrite SQL for both DBs. I'd do it on ever project if I could.
- kristiandupont 4y agoI know that a lot of people do this but I would have very little faith in my tests if they were run against a different type of database than my production one.
- wizofaus 4y agoLikewise, if there weren't also integration tests that ran against a DB engine more similar to that used in production. But no unit test environment is ever going to emulate everything in production, nor should it.
- damagednoob 4y ago> I would have very little faith in my tests if they were run against a different type of database than my production one. Hence why they were run against MySql on CI.
- kristiandupont 4y agoAh, I missed that part. Makes sense.
- mradek 4y agoI spin up a new database per test suite. I use pg and test suites run in parallel against their own db. It’s pretty cheap with CREATE DATABASE helpers plus using container means little to no headache.
- fastball 4y agoWhy would you also run the tests against SQLite during CI if prod database was MySQL?
- tabtab 4y agoSwitching DB's does happen, but it is generally rare in my experience, and usually a strategic mistake. Those who do it usually underestimate the migration time. It's not economical to spend a lot of time up front to prepare for a scenario that happens once in a blue moon. The main reason to write mostly generic SQL is so new hire-ees can get up to speed.