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

> I can write a test for the db logic, too.

I agree but I would add that having testing niceties like branch coverage isn't really possible for SQL queries / PGPLSQL functions.




But you don't need that. That's an issue for whoever implemented your DBMS.

To test your queries all you need are unit tests of the standard form: for given inputs, assert(output).


I disagree. If my query calls a PGPLSQL function, I'd like to be able to test and branch cover it.


If you’re the one implementing the functions (or even if you’re not), there are tools such as pgtap that can help you with testing. I’ve used pgtap successful on a number of projects. There’s also no reason you can’t test the behavior of functions through a driver in some other language, though you’re now one step removed.

I’m not aware of any coverage tools, though it’s been a while since I’ve looked.

https://pgtap.org/


Or you could test behaviour, and not code. For example, have a test as part of your app's general test suite - insert a row, read it back and check the generated column value is what you expect.




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

Search: