Follow

I've been favoring a more style of writing my code recently. Lots of small compostable functions with a single responsibility.

One thing I struggle with is how to test everything. Should I unit test each bite-sized function (even if they're pure)? Should I just worry about an integration test of the larger system?

@zstix
If you can muster the willpower, more tests never hurt.

@zstix it depends on the language really, if you have a solid typed langauge a pure function should be safe, but if it's javascript, well, you're kind of bound to testing and testing everything.

@zstix of you're coding mostly by yourself, then I've always found integration testing to be more helpful, and productive.

if I unit test every little thing I just end up with hundreds of it-does-what-it-does type tests which miss a lot of problems, and really slow you down if you refactor.

@zstix
My advice is: test interfaces so that you are forced to write them.

Unit testing means dividing your work to small units and testing those. Unit is a small piece of functionality that is meaningful for your application.

I would see whether a single function forms a small _and_ meaningful piece of application logic and then decide whether I should test it independently or together with other functions.

Going like this will force you to develop a nice interface for your code.

Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.