News for hackers. Stuff that matters.
Re:Bruce Eckel: Strong Typing vs. Strong Testing (2003) by silentbicycle on Tuesday September 21, 2010 @05:25PM (#1714165)
How do you ensure that the unit tests are correct?
Re:Bruce Eckel: Strong Typing vs. Strong Testing (2003) by auxbuss on Tuesday September 21, 2010 @05:44PM (#1714213)
Unit tests are "correct" by definition, because they represent the specification for the code that they test.

You aim to encapsulate all the intended behaviour in your tests.

Thus, when you encounter a bug, you start by creating a test that replicates the bug, correct the test to the expected behaviour (so it now fails), then fix the code. That is: red, green, refactor.

Not only do you fix the bug, but you improve the specification and improve the efficacy of your tests.

In the way that you cannot pragmatically prove that code has no bugs, neither can you prove your tests are correct (bug-free). But by having a test suite that can run continuously, and that you add to, you are increasingly improving code quality and, most importantly, ensuring that regressions don't occur.

Re:Bruce Eckel: Strong Typing vs. Strong Testing (2003) by silentbicycle on Tuesday September 21, 2010 @06:42PM (#1714385)
> Unit tests are "correct" by definition, because they represent the specification for the code that they test.

No, those are acceptance tests. (It's really too bad they can't be the code. Talk about DRY!)

Besides, how does one write tests for bugs they don't know about? (Or can they only be written after the fact?) Wouldn't it be helpful to have some sort of declarative specification so that the compiler itself can generate exhaustive tests?