Re:Objection to ORM Hatred
by kristiandupont on Monday January 16, 2023 @03:36AM
(#34398345)
I 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.
Likewise, 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 every going to emulate everything in production, nor should it.
Re:Objection to ORM Hatred
by damagednoob on Monday January 16, 2023 @04:48AM
(#34398787)
> 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.
Re:Objection to ORM Hatred
by kristiandupont on Monday January 16, 2023 @05:17AM
(#34399022)
Ah, I missed that part. Makes sense.
I 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.
* * *
Switching 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.
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.