- 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
I'm just sitting here, waiting for the first guy to post that one XKCD comic due to the last line.
Admin
I was just sitting here waiting for someone to post "Fisrt!". You disappointed me!
Admin
Now I understand why at CS class they told me to first write a test that fails...
Admin
Gru meme!
We write unit tests! / The tests should fail! / They pass / They pass
Admin
It also reminds me of this little song
99 little bugs in the code, 99 little bugs in the code
Track one down, fix it, patch it all around
102 little bugs in the code, 102 little bugs in the code
Admin
In my opinion, the best testing framework for Python is PyTest. But even if Unittest is perfectly fine...so why?!?
Admin
I aim to (dis)please.
Admin
And this is why you test your test framework, including writing negative tests!
Admin
OK, fine: https://xkcd.com/1172/
Admin
“If ever you fear there are mice in your walls, listen to common wisdom and buy four fine cats. But listen to Zjing also, and release a single mouse among the cats every day—to make certain they have not forgotten how to hunt.” Credit http://thecodelesscode.com/case/182
Admin
So did all the other test writers call .setFailed(True) for a pass and .setFailed(False) for a failure, or were they using it like a sane person would expect and the tests passed because they were actually broken and the test framework was treating them as successful?
Admin
This is one of the best WTFs I've ever seen come from a copy/paste - and it didn't even come from Stack Overflow!
Admin
What if the test does not break out of the test case after a fail?
.setFailed()
another test that succeeds
.setPassed()
And the passed variable is set back to True...
Admin
I come here daily for the .setFrist(True) memes. Today I am disappoint.
Admin
This is one of the best WTFs in a long time.
Admin
Ran into a similar issue recently, but with Python itself. I had some code that (basically) did this:
m = Mock() m() m.assert_not_called()
The test passed, which felt like a WTF at first. Stepping through it in a debugger the issue was pretty obvious -- the version of Mock we were using didn't have the assert_not_called() method, so it was a no-op. Needless to say, this wasn't the only test that used the non-existent assert method.
tl;dr -- you don't have to bake your own unit test framework to wind up with misleading unit tests.
Addendum 2018-04-17 12:27: (Well the formatting in my code is messed up, but you get the idea.)
Admin
At a large corporation that shall remain nameless, there is a developer tools team that provides some recommended Ant config for building Java code.
All this works just fine, and if you're using regular
assertEquals
and such methods, you're fine.We had a junior dev who thought, "those are ugly, I'll just use the
assert
statement." And he was entirely reasonable in his assumption that anassert
statement should do what it plainly says.Of course, in keeping with the Java tradition of fundamental language features being horribly broken, by default the assert statement doesn't do anything. It's removed by the compiler.
And the dev tools team didn't configure their test framework to set
-enableassertions
. Okay, fine, it's an oversight.We, of course, discovered his tests were passing spuriously the hard way.
I emailed the dev tools team to alert them to the problem:
"(Explain the problem...) Please enable -ea on testing frameworks." "You should use the assertEquals() method or raise an exception directly..." "Yes, I understand the thing I explained to you. The issue is that junior devs don't understand this, and this kind of breakage is silent and caused a high severity break in production." "We can't change that, it would break a lot of builds." "Teams trying to deploy to write tests to catch problems before they get to production, we want builds to break. Just roll it out slowly."
At the mention of effort on their part, radio silence.
Admin
I don't suppose it's worth pointing out that the Pythonic way of writing unit tests is to add them at the bottom of the module. You know, "if name == "main"."
Maybe this is a Python framework, where such simplicity is derided.
Or maybe, just maybe, this is yeat another case of TDWTF not actually understanding the language they are talking about.
Admin
Apparently your bar is very low on the Kelvin scale.
Admin
Easily fixed:
Admin
Bullwinkle variant: reallySetFailedForSure()
Admin
"My module is unit."
"Huh! My module is unitter!"
"You're both losers! My module is unittest!"
Admin
It hurts