We need another suffix. “Considered Harmful” is too overused.
Considered harmful considered harmful?
Can’t agree with this enough. One of the biggest problems I see, especially with people using mocking frameworks, is that they’re not testing behavior, they’re tracing code.
This test can actually be useful.
I had a monotonically increasing integer to identify objects in the system. These IDs would be publicly visible, inviting people to scrape them, so I primed the RNG and shuffled the bits. They have all the same properties I need, but it’s far less likely someone will iterate over them.
I had a test that throwing a particular number into the shuffle got a particular number back out. This was deliberately a change-detector test. It didn’t care if a shuffle was done reversibly, or maintaing the same number of 1 bits, or do anything more to verify correct behavior than this article’s second example.
The test failed once because the Ruby stdlib random number generator changed and the array was sorted differently. Without this test I would’ve started generating duplicate IDs. I was able to handwrite a new stable version and the system continued happily. The test is still there.
Heartily agreed. Especially for functions I’ve optimized I’ve found it helpful to retain the inefficient but supposedly equivalent definition and test that the two achieve equivalent results for all inputs.
Literally days if not weeks were thrown away dealing with change detector tests at a former startup I was at. I’d like to blame it on https://code.google.com/p/pymox/ but really the person who wrote all those tests didn’t understand what mocking was and wasn’t for.
for real, those tests sucked though. geez what a mistake