Code that is untestable really annoys me. The following things make oo-code untestable:
Are there more warning signs?
(Part 2, for Developers) In my last post, I argued that “untestable code” is code that cannot be efficiently unit tested. Today I'd like to walk through my top five anti-patterns that make writing unit tests painful.
In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures—are tested to determine whether they are fit for use.
TDD - Test Driven Development is a Development-Testing methodology that helps developers to achieve Speed, Robustness and Quality with its specifically structured mechanisms. It is a software development approach where a dev write unittests before the application code.
See the following blog post by Miško Hevery: How to Write 3v1L, Untestable Code.
None of those things make code untestable. They may make it harder to find edge case bugs but, provided you have fully specified the success criteria for testing (and test-driven development eases this), all you have to do is pass the criteria.
TDD can apply to the behaviour of specific parts as well as the project as a whole, so you can easily test very small components. But, it's meant to test the results, not the means by which those results were obtained.
Provided the tests are passed, you have met the requirements. If there are bugs following that, this is an issue with the tests, not the code being tested (in which case the tests should be modified to catch the previously unforeseen problem).
You should not care (in terms of delivery of functionality) whether there's a while statement in one of your constructors. You should ask yourself what business requirement mandates that? I strongly doubt your client will deliver a list of requirements including "inheritance limited to 4 levels". They may well list "bug-free" as a requirement but you'll have to negotiate them down on that one :-).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With