DEV Community

Discussion on: Is testability a reason to change your design?

Collapse
 
dwd profile image
Dave Cridland

I think that "BECAUSE TEST!" is roughly the same as "BECAUSE SECURITY!" or the nebulous "BECAUSE UX!". What we're after is greater confidence in the software's quality, and quality is measured along many axes, often with a trade-off to be made. Focusing exclusively on test as an end-goal is a deceptive thing because software can be well-tested and completely useless.

So for some of my own green-field projects, I do very heavy automated testing - but I didn't need to have that influence the architecture to do so. It did influence the implementation, though - Spiffing, for example, is carefully written to avoid "bushy" branching, reducing the test effort required. The test framework is written to be data-driven, too, so that users can work with their own test data as well as mine.

On the other hand, some projects don't lend themselves well to automated testing at all - I've never seen good tests for the server-to-server portions of an XMPP server. Maybe it's possible with significant work, but I suspect it's one of those things more effective to write and manually test heavily. The bugs are complex sequential issues, difficult to replicate in any useful way in automated tests without having to write half a simulated network stack. So instead, my effort goes into manual test, and support for that.

Small pieces of code don't get tested not because they're unimportant, but because one can (hopefully) manually prove them.

So I'd note that:

a) Testing is a crutch we use to avoid provability. If we could usefully prove code, then testing it would be superfluous.

b) Testing only works if the tests themselves are correct. Testing is only useful if the tests are testing that which might fail.

c) The goal is not test. The goal is confidence.

Collapse
 
n_develop profile image
Lars Richter • Edited

I think that "BECAUSE TEST!" is roughly the same as "BECAUSE SECURITY!" or the nebulous "BECAUSE UX!".

It sounds so negative, when you say it like that. :-) But to be serious: In general you are right. Testing/Testability shouldn't be the main goal. No doubt here. Nevertheless, sometimes I make decisions, like the one mentioned in the post (introducing an interface), to make something testable. Nothing more. Just make it testable (or as you like to say it "BECAUSE TEST!" ;-) ).

c) The goal is not test. The goal is confidence.

And we should always keep in mind: A working test suite gives a lot of confidence.

Collapse
 
dwd profile image
Dave Cridland

Absolutely - a working test suite is a great way to get confidence. A working and audited test suite even more so.