

How do you do Real-world Unit Testing? - toxik

I often hear about the benefits of unit-testing and how great it is to have a complete test suite and so on, but I've many times found it way too cumbersome to actually make unit-tests for the code I write.<p>For simple functions that only operate on scalables and return scalables, unit-testing is easy. However, it becomes a wildly different story when things like database connections, configuration files, memcached servers etc. are in play.<p>How do you test something like an IRC connection? Obviously you could set up a phony socket which doesn't really use the network, but that would in some cases defeat part of the test.<p>Dear YC, how do I make unit-tests with auxiliary resources?
======
yan
I think testing things like connections, caches, etc are outside the scope of
unit testing. What you probably want to unit test is how your code handles a
malformed NICK command in an IRC connection, or random input, not the entire
connection as a whole.

You write unit tests for these handlers and when that's done, you can write
scripts that are grander in scope and nature. They can build and tear down
connections, or perhaps drop it in semi-random intervals. As far as I know,
unit tests are made to test fairly small-scale blocks of code and bigger
frameworks and scripts can test whole subsystems.

------
stcredzero
Difficulty Unit Testing often reveals deficiencies in design. Is your system
divided into largely orthogonal parts?

