• LXE (unregistered)

    Don't unit test the library/framework code

    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).

  • (nodebb)

    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?)

  • LXE (unregistered) in reply to Mr. TA

    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.

  • MaxiTB (unregistered)

    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.

  • (nodebb) in reply to Mr. TA

    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.

  • (nodebb)

    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.

    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:

    The string returned by the ToShortTimeString method is culture-sensitive. It reflects the pattern defined by the current culture's DateTimeFormatInfo.ShortTimePattern property. For example, for the en-US culture, the standard short time pattern is "h:mm tt"; for the de-DE culture, it is "HH:mm"; for the ja-JP culture, it is "H:mm". Note that its value can vary depending on the .NET implementation and its version, the operating system and its version, and user customization.

    Overall conclusion: assuming anything about the output of ToShortString() is a bad idea.

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    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!

  • Giulio (unregistered) in reply to Mr. TA

    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.

  • LCrawford (unregistered)

    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!

  • Xorium (unregistered) in reply to Steve_The_Cynic

    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.

  • Argle (unregistered)

    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?

  • Shiwa (unregistered)

    Even a broken test is right once an eternity.

  • Randal L. Schwartz (google) in reply to Argle

    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.

  • MaxiTB (unregistered) in reply to Argle

    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.

  • Duke of New York (unregistered) in reply to LXE
    1. The test suite is not a sandbox for developers to record their personal learning struggles.
    2. Unit tests don't identify integration defects. Integration testing does.

    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.

  • (nodebb)

    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.

  • (nodebb)

    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

  • Zatapatique (unregistered)

    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.

  • Mateusz (unregistered)
    Comment held for moderation.
  • (nodebb)

    CI tools? Remy certainly is optimistic about the government ponying up for something like that for us poor zhlubs.

  • WTFGuy (unregistered)
    Comment held for moderation.
  • (nodebb)

    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.

Leave a comment on “Testing Your Date”

Log In or post as a guest

Replying to comment #:

« Return to Article