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

You never use DB-specific features? We use postgres' JSONB column type which precludes using something like sqlite in tests.



Why would it? Sqlite has had json support for years. The ORM can abstract over column types, and functions.


Most of our projects are mysql, and in those we don't use any db-specific features. Those all use in-memory sqlite for tests. Only in one of our projects do we use jsonb with postgres, that one does use postgres for the tests as well. Though, that project probably didn't need it - we're just sort of stuffing semi-regular data from another system into it. It would have worked just as well as a text field that was parsed as-needed, since as far as I remember we don't query it directly, only query based on other columns in that table.


You can run tests in MySQL in memory almost as easily.

   database-autotests:
       volumes:
          - mysql-autotests-volume:/var/lib/mysql

   volumes:
       mysql-autotests-volume:
       driver_opts:
       type: tmpfs
       o: "size=2G,mode=777"
       device: tmpfs

It's also very fast and allows to test the code on the same database, especially if you have something MySQL-specific.


Not sure what that is, docker? None of the several dozen projects I'm referring to use it.


Yes, that looks like a docker-compose config. But, it doesn't really matter. The point is that you could run MySQL in a way such that its storage (the actual data files) are on a virtual filesystem running in RAM.

It's a nice way to do it, IMO, because I prefer testing against a real DB instance in my projects anyway (rather than pretending that a unit test against a fake 'FooRepository' interface proves anything at all).




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: