- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Well the last one is actually a brillant one.
Now You know how to generate test code for virtually any percentage of real code by just writing a simple script (pseudocode):
for (x = 0; x < maxtest; x+) { print "s = "";\n"; }
As I said Brillant :smile:
Admin
That first one is really checking whether
convertToRelativeDate
produces consistent results. I've had the bad fortune to encounter classes where basic assumptions like that were not maintained, and they were horrible.Though I do have to ask “relative to what?” If it's relative to now, today, then fun happens if a midnight tick happens between the two calls…
Admin
My first thought was that if convertToRelativeDate is using system epoch as the basis, the comparison is going to be very, very implementation dependent, and the output unpredictable.
The second one reminds me of an old Soviet era joke. The Central Committee 5 year plan calls for shoe factories to turn out the maximum number of shoes, so State Shoe Factory No. 1 spends 5 years churning out baby shoes. For the next 5 years, therefore, the plan calls for factories to generate the maximum weight of shoes. So the factory turns out industrial boots with steel toecaps. The Central Committee thinks hard about this and somebody has a brlliant idea. "We'll tell them to produce the maximum value of shoes."
A week later the purchasing manager of the factory starts looking for someone who can make solid gold hobnails.
Admin
That second one looks like a prima facie case of professional misconduct, or even fraud.
Admin
It also calls the method on two different objects bpm and newBpm, which might not be the same.
Admin
I'm glad to see that the code is so generous. If that poor snippet had its candle withheld...
Admin
So they encourage the pay-per-line programming style, too?
Admin
So, where is bpm defined in the first snippet? How do we know it's the same as newBpm?
So, either my browser displays things wrong, or there are a lot of `s=""` in the same line OoFiled Under: Just saying
Admin
Also, what does this mean?
How does it relate to the test? Were Alice and the contractor working for Salesforce?
We have one giant line with a bunch of junk that doesn't do anything. What's the definition of "coverage" here? Remy's statement seems to imply that they're really talking about the test suite's LOC count.
http://i.ytimg.com/vi/6zj5eyE1qUA/hqdefault.jpg
Admin
I like to imagine that alice (maybe even @aliceif) was the entire salesforce, translating into the only person who bought the product. And she just refused to
updatebuy more versions of the same software until the darn "coverage" had been fufilled. Since nobody understood what she meant by that, they just added random lines of nothing-code!Filed Under: Yeah, I am as lost as you. @Remy
BITCHCOMPLAINEXPLAINAdmin
Coverage for unit tests is typically measured as either percentage of statements executed or percentage of branches taken. Less common is percentage of functions entered or percentage of lines executed. Clearly the contractor assumed it was statement coverage, but Remy's statement points out it's lines covered.
I believe the article is saying that the code you see was in the real code, tucked away in an unused function, so that writing one unit test that covers that function achieves 75% line coverage for the class.
Admin
Coverage ...?
What's that?
Admin
Ahhhh....that makes sense now. I looked at it as being another test.
Admin
Exactly. It's unknown. It's mysterious. It's something you would never think of ever needing. And thats exactly why you need it (and at least 75% of it, too! Otherwise, why even bother?)
Filed Under: selling products seems too easy
Admin
No it doesn't. The method is called on bpm and newBpm. Perhaps bpm is a known "working" implementation and the test only checks that the behavior of the new implementation is consistent with that of the old one.
Admin
or there is some randomization and the test is to make sure the marginal error after decimation is zero.
Admin
I like how Remy's attempt to be funny breaks the formatting.<There's usually spacing oddness near the cornify script for some reason>
Admin
s/s;/s;\n/g FTFY.
Also WTFTFY, LTPTFY, NYHTPTFY
Admin
But the first test actually checks method call result of bpm instance (likely declared somewhere else and containing reference/old implementation) against result of newBpm instance method call.
And the second code has nothing with coverage.
Admin
"At least there IS tests"?
Admin
Fun fact, this page unrecoverably hangs Chrome for Android. You have to actually force close the app.