- 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
Why? First, it's one of the best ways to learn it. Second, it's also one of the best ways to learn that it has broken its part of the contract (due to an untimely update, a misconfigured environment, or any other broken presumption).
Admin
I think the developer used a test to test the output of the ToShortDateString method, instead of "believing" the documentation (because obviously, everything is a lie, right?)
Admin
Strawman. Not all, of course. But anyone who ever ported a complex software product from one ABCDXYZ compliant system to another knows that some documented promises are misleading at best.
Admin
People love to write test for frameworks. And I think they do it, because that code was already way more tested than they could ever muster the time to write tests for and spoiler, obviously those tests never fail. Well, except you are a complete dimwit and write a test like that obviously.
Admin
That does seem to be a possible explanation, perhaps they felt it easier to write a test than to make a new console app or use LINQPad and then forgot to delete the test afterwards (indicating they don't do real PRs).
It's worth mentioning though that ToShortString()'s output varies based on culture info used, so it's not immediately apparent just from the docs what will be output depending on what else may be happening in the environment.
Admin
Of course, but the (current) documentation at https://learn.microsoft.com/en-us/dotnet/api/system.datetime.toshorttimestring?view=net-7.0 is quite clear that the output is culture-dependent, in a nice pale pink-purple box that says:
Overall conclusion: assuming anything about the output of
ToShortString()
is a bad idea.Admin
Europeans are so used to chastising Americans for failing to localize properly and hard-coding American date formats. It's not too often that we get to do that the other way around like in today's code!
Admin
Would make sense. Then, either you don't commit the test, or you rewrite it in a way that will work irrespective of the current date.
Admin
Clearly before the tests are run, Peabody and Sherman have to set the Wayback Machine to 26 August 2016 and go to a locale with the matching culture setting. Then the test will pass!
Admin
Or they wanted to test the configuration that would lead to the desired output from the framework code. In that case it is logical that the test exists. Still stupid to use system date of course.
Admin
Oy! Over on the "Not Always Right" site is a recent story about someone who didn't like the usual security questions for his bank account. He was told he could suggest one. His bright idea for a security question? "What is today's date?" Strange that it only worked one time, innit?
Admin
Even a broken test is right once an eternity.
Admin
My favorite hypothetical challenge/response when you know it will be asked by a live person is:
Q. "What are you wearing?"
A. "None of your business!"
I've heard stories of this triggering in real life, with the expected hilarious results.
Admin
That is actually not a bad question to avoid dictionary lookups. On the other hand you can set the logon failure limit to 3-5 attempts and then auto lock the account, would work as well.
Admin
Testing the behavior of dependencies, rather than the thing that depends on them, is a cargo cult practice that destroys the value of a test suite if tolerated.
Admin
Writing unit tests that test the framework is how you get pass %'s up (assuming the test is implemented correctly). For every metric, there's a stupid workaround to fudge the numbers.
Admin
DO test framework and third party code... just don't co-mingle/conflate it with testing your own code. Over the decades this practice has saved countless hours when the inevitable breaking upgrade or technology/vendor/product switch occurs and it is necessary to test the sub-set of behavior that we actually use and count on
Admin
If they wanted to test the ToShortDateString method, the test should have been called TestToShortDateString instead of TestNewDate. And they should have used a fixed date instead of the current date.
Admin
CI tools? Remy certainly is optimistic about the government ponying up for something like that for us poor zhlubs.
Admin
Remind me of the struggle of my project to integrate meaningful test suites into a project that has been going for 20+ years without.
When "testability" is no design concern, strongly coupled code (globals!!) doesn't become an obvious issue for way too long.