• Quite (unregistered)

    Both values are not equal, but some both values are more not equal than others.

  • (nodebb)

    At least this appears to be actually comparing something that conceivably could come from the actual code under test to something else.

    I've seen tests that compare a hard-coded value to an identical hard-coded value, and tests that compare a constant to itself. In the same test class. The tests that run actual code from the class under test and (if someone was being especially diligent) check that the result is not null were in fact the best ones in the codebase when I started this job.

  • Quite (unregistered)

    This always gets me:

    Console.WriteLine(pf + pt + len + tableval + databasevalue1);

    Like, you're writing a message to the user -- how about if you put a space between each element so you can see where one ends and the next one starts?

  • Richard (unregistered) in reply to CarrieVS

    That's pretty good; but .... <For those that have seen the Monty Python "Four Yorkshiremen" sketch, I'll say "Luxury...">

    My favourite test was a test which setup a mock of the object which should have been under test (all the other tests in the TestFixture were testing the right object); it painstakingly set up the mock to behave in a certain way, and then tested & asserted that the mock had behaved as it was set up to do. I could remove the entire implementation of the object under test, and the test still passed. :)

    As a bonus point, I'm going to pick up that the author didn't understand the difference between the two parameters passed to "Assert.AreEqual" ("expected" and "actual") because they use the same variable for a different parameter in different places. For example, it would not technically be correct to say "Assert.AreEqual(list.Count, 3)" because the "expected" parameter should come first, even though it grammatically isn't how you would say it. Hence the reason why NUnit introduced a new approach to the syntax a couple of years ago, allowing you to say "Assert.That(list.Count, Is.EqualTo(3))".

  • (nodebb) in reply to Richard

    Yeah, that's exactly that I was talking about. It's in all the DAO tests in our codebase, except the one I wrote. (To be fair, most of the data-access code is hell to test, but no excuse for pretending to test it.) Also somewhere in the sidebar on WTDWTF, where I posted it.

    I don't work with a Richard, but maybe you've got code from the same supplier we got this from.

  • (nodebb)

    Just wondering if the function is supposed to be called with character literals (ascii) (or a summation of a few) for the pf argument.

    61 '=': ensure not equal
    76 'L': random: skip check
    164 ('ñ' == '='+'g'): TIME!
    160 ('á' == '='+'c'): date compare today
    270 ('?' == '='+'d'+'m'): date compare tomorrow
    default: compare values
    

    The only problem is that the first line of the function contains con.Substring(pf-1,len), which uses it as an index into the con parameter to determine the databasevalue1 variable. I'm not sure that I like what that implies about their database.

  • nb (unregistered) in reply to CarrieVS

    "I've seen tests that compare a hard-coded value to an identical hard-coded value, and tests that compare a constant to itself. In the same test class."

    I got one from an offshore dev that was this gem of perl: if(uc($testString) eq "warning"){...

    So, they uppercased the string and compared it to the lowercase string "warning". That test will never equate true. That was one of many similar examples of not just poor coding, but flatly wrong coding. I was given a 5000+ line mess of this and told to make it work in a week. I made lots of $$$ on OT that week.

  • Andrew (unregistered) in reply to Richard

    Strictly speaking the Four Yorkshiremen is not a Monty Python sketch.

    https://en.wikipedia.org/wiki/Four_Yorkshiremen_sketch

  • Ulysses (unregistered)

    case hash("Paula"): Console.WriteLine("Brillant!"); break;

    case 4: Assert.AreEqual(pf, 4, "Both fours are not equal"); Console.WriteLine("Chosen by fair dice roll"); break;

  • Mike (unregistered)

    Not as bad as the tests I've found that use the value from a struct in the code as an input and verify it against the 64 bit uint the code unions the struct with. I'm pretty sure C++ unions work as advertised and we would rather verify an input to the system sets an appropriate output, rather than verifying that the output of the code matches the output of the code.

  • (nodebb) in reply to Quite

    SPACESPUNCTUATIONANDLOWERCASELETTERSAREONLYAFEWCENTURIESOLDSOWHOSGOINGTONEEDTHEM

  • Noughmad (unregistered)

    I'll go ahead and try to at least give an explanation for the pf variable. It looks like the function is checking individual parts of a string returned from some kind of database. Apparently, at position 61 there is some kind of a zero-padded number, then at 76 a random value, then two dates at 160 and 270. Strange that time is checked (well, "checked") at 164, while that should be the MMdd part of today's date. Maybe they changed the date format without updating the test function. This makes sense of both the substring() call and the switch. All other fields are probably strings, or something else that can be compared directly as strings.

    Note that what I wrote here doesn't in any way mean that the code is good, acceptable, or that one should not kill it with fire, and then kill the fire with water afterwards. It is Excellent, though!

  • GordonFreemanK (unregistered)

    I like how the programmer took the time to add the (optional) reason parameter in the asserts. Particularly the last one, which reads as "assert that the actual value is the expected value, and when it fails tell the user than the reason why it failed is because the actual value was different from the expected value".

  • snoofle (unregistered) in reply to Richard

    Sadly, most of the places I've worked only care about the percentage of LOC that are referenced (not necessarily used) by the tests, and that all the tests pass. So nonsense like this pervades the test suite: public void testWidget() { try { Widget w = new Widget; } catch (Exception e) { } }

  • Pista (unregistered)

    "I don't think mindlessly adhering to ANY methodology or paradigm is the right approach" - I agree. Right now I'm being tortured with Continuous Functional Testing.

  • Bernie (unregistered)

    That's a great step into the testing world for a COBOL programmer! Oh yes, it's COBOL he had in mind: one long string containing all the data at their specific positions...

  • (nodebb)

    What...? I clicked on "TDD" and it made my screen fabulous.

  • (nodebb) in reply to billhead

    Read the page source for the article...

  • face generator (unregistered)

    i am always looking for some free stuffs over the internet. there are also some companies which gives free samples.

  • group buy seo (unregistered)

    This could be the right blog for everyone who is desires to be familiar with this topic. You already know much its practically not easy to argue along (not that I just would want…HaHa). You certainly put the latest spin with a topic thats been discussing for decades. Excellent stuff, just great!

  • seo tools group buy (unregistered)

    This could be the right blog for everyone who is desires to be familiar with this topic. You already know much its practically not easy to argue along (not that I just would want…HaHa). You certainly put the latest spin with a topic thats been discussing for decades. Excellent stuff, just great! group buy seo

  • litterboxfurniture (unregistered)

    I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while. Its as if you had a wonderful grasp on the subject matter, but you forgot to include your readers. Perhaps you should think about this from far more than one angle. Or maybe you shouldnt generalise so considerably. Its better if you think about what others may have to say instead of just going for a gut reaction to the subject. Think about adjusting your own believed process and giving others who may read this the benefit of the doubt.

  • disaster recovery services (unregistered)
    Comment held for moderation.

Leave a comment on “Excellent Test”

Log In or post as a guest

Replying to comment #468965:

« Return to Article