Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Business logic doesn't require that you use DateTime. Business logic requires that the software understand dates in a certain way.

Some unit test styles enforce a given API at all levels in the code. Others restrict themselves to tests through certain restricted APIs.

For example, the SQLite code tests through the API, so it's possible to do major revisions of the code without changing the tests. The choice of how date logic works is invisible to the tests. Date tests can be done through SQL, without testing the actual code functionally equivalent to DateTime.

I prefer the latter. I liken it to building a bridge. The main test is "can you safely get traffic from X to Y", with other tests related to maintenance, beauty, environmental impact, and so on. This can start with a stone bridge, then a truss bridge, or a suspension bridge.

It's also possible to have tests like "there must be a pillar here, a truss there, an arch up there, and a screw over there", which requires that the bridge must be an iron bridge using a Pratt truss design, with three support columns made of granite.

Rebuilding/refactoring to even, say, a Parker truss would require rewriting some of the tests. Rebuilding/refactoring to, say, a truss arch requires a lot of rewritten tests.

But under the high-level tests, like for SQLite, major redesigns don't require major changes in the tests.

If at the start you know that you want a specific bridge, and you just have to work on it, then go ahead and write these very specific tests. Just remember that major refactors will require a lot of rewritten tests.



This makes a lot of sense to me. SQLite has the reputation of high reliability and thorough testing, maybe there is a lesson there.

In my opinion the value in testing is verifying what an interface should do, not how it does it.


SQLite gets it in part from very rigorous coverage testing. See https://www.sqlite.org/testing.html if you haven't already.




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

Search: