Today's Tautology: Software is Software

Ovid on 2003-10-30T21:05:22

Would you move software into production if it failed to perform to spec five percent of the time? Of course you would. In fact, you probably have. This sort of things happens all the time and we call it "a bug" (or "a feature" if we want to alienate our user base). So rephrasing the question: would you knowingly move such software into production? Probably not. Admittedly, there's a certain ill-defined level of complexity beyond which bugs are unescapable, but a five percent failure rate is ridiculously high, particularly if the feature that fails is critical to the overall correct operation of the software.

Here's a hint to all developers doing TDD (test driven development): tests are software, too. While we admittedly do some strange things in tests (I override function definitions left and right), for the most part, good software practices apply to tests because tests are software. It doesn't matter if you're not shipping these tests to your customers (though I think you probably should). What matters is that software is software and if you write perfect code for your customers and lousy tests, you still have a substandard product.

Right now, I'm dealing with intermittant software failures in tests. As it turns out, the developers who wrote these tests knew that they would likely fail at some point, but rather than make sure the tests always worked, they accepted that they would usually work. Maybe this is fine for Windows users who accept that the occassional BSOD is an acceptable price to pay for the ability to create Powerpoint presentations, but as a developer, I am the customer for those tests that he's writing. I can't pay that price because shouldn't be expected to keep track of which tests might fail and which might succeed when I'm dealing with thousands of tests. It's like having an error log full of "unitialized" warnings. After a while, you learn to ignore the error log.

Fragile code is also bad, regardless of whether or not it's in a test. We have tests where we compare stack traces in error logs. The tests assume that the trace is going to be an exact match, if someone fixes a module in a completely different section of code, they have problems in running the test suite because they may have affected a stack trace in an apparently unrelated set of tests. Right now, I'm working on testing the stack trace functionality directly and then the stack trace tests will use regular expression rather than expect an exact match. Once done, we'll have much more robust tests.

We also have a several helper functions that are cut and pasted into many different test programs. These should have been refactored, but weren't, so if there's a problem, I need to grep through the codebase and find all of these problems. I don't know if anyone at this company has ever done such a large-scale fix of the code as I'm doing, but having a test suite where the rules of good software development apply would have made this job much easier to deal with.


I mostly agree.

pdcawley on 2003-10-31T08:11:57

The problem with the test that expected an exact match only becomes a bug in the test when you change the output. So, you roll back your changes, refactor the failing test to accept more generic input, make sure it still passes without your changes and then redo your changes (consider doing a quick smoke test by deliberately breaking the thing it's supposed to test to make sure it fails correctly too).

With TDD you are holding your tests to the same standard as your code; tests should be good enough for right now. Keep it simple so you can change it easily. The original, fragile, test was Good Enough up 'til now. The time saved by not making it generic meant more stuff that added direct customer value could get done, and that's a Good Thing.

However, rape and paste functions are Evil, Bad and Wrong and should be excised at every possible opportunity as part of your general refactoring. Accept the blame for letting it happen, fix it, and move on.

Absolutely!

jordan on 2003-10-31T16:57:45

  • While we admittedly do some strange things in tests (I override function definitions left and right), for the most part, good software practices apply to tests because tests are software.

I couldn't agree more.

Being an ardent advocate of TDD, I wouldn't think of writing a line of test software before I have the tests for that test software in place. Of course, the test-tests are also software and require that tests for them be written first and those tests require that tests, well you get the idea.

Re:Absolutely!

chromatic on 2003-10-31T20:05:30

The nice part about TDD is that the tests test the code and the code tests the test. That is, if you write a test, make sure it fails, write the code, make sure it passes, you can avoid most of the worry.

Writing a good test library is harder, though.

Re:Absolutely!

jordan on 2003-10-31T20:38:42

It was a joke, not an attempt to find a flaw with TDD...

Re:Absolutely!

chromatic on 2003-10-31T22:22:43

Oops. Heh. Spend a year writing a book on Extreme Programming. I might be permanently incapable of telling when people are serious about holding silly ideas or just joking.

Re:Absolutely!

pdcawley on 2003-11-02T16:07:12

I like it best when people are silly about holding serious ideas.