- 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
This code also has some problems with the null key and null values. Those are unusual but are permitted by the language. Probably the programmer "just happens to know" that the application at hand doesn't actually use a null key or null map values BUT THAT DOESN'T MATTER. That is forbidden global knowledge and should be ignored.
I've spent way too long bending my brain on this method and I'm not 100% certain I got the multiple negation right. I tried to rewrite it to see if breaking it down will clarify things, and I think I got it, but I'd need to make up some test data to be sure.
Admin
"The unit test method should worry about that kind of plumbing, not a supporting method which exists to perform a check." - Do not forget DRY.... if there is a reason to "sleep" then there should be only one place in the entire codebase that does that sleep [this is also SRP from SOLID]. Highly doubtful that the "unit test" is the right place to do it either....
Admin
I can imagine a manager taking pride in how long their unit tests take to run.
Admin
Not even any comment on the empty
catch
! I find it hard to see howthread.sleep
could throw (but I'm not really up on Java or C# or whatever this is), so it's likely completely unnecessary anyway - but if it somehow does we'd probably want to know why rather than just have it silently ignore the error!Admin
So. it could also have one or more of the following reasons: 1.) The language standard does not correspond to what was found in the literature (in my case the German one which is always just a few years behind) when the chief developer started. Does anyone else know 'goto' combined with global variables instead of even a single function or local variable? Actively used in 2022? 2) "The compiler has a bug there, you have to do it by hand. There is a piece of code you can copy..." (Apart from copying... it was about Sort... and in the time I was there the compiler vendor was changed, and also there it went a few versions further, but if there was a bug there before...) 3) A boss who wants to have everything logged to the second ("3 minutes nothing done, because waited for {...}" <- no! this is not a joke!) and always looks into the pull requests - and complains why it took so long for such a simple correction (a single condition changed). If you took a long time, you will eventually build in something nonsensical, which does not break anything (see point 1) and whose result is also used. For example a possibility to create files with a maximum size when zipping, instead of using the possibility built into the zip program... or did point 2 also play a role there? Never mind....
And yes, such software can gain market share even today.... In the meantime I have cancelled there... despite an offer with much more money (30 %), much more vacation (50 %!) and also on top of a lower working time (only 10 % less). And that was at the beginning of the year, so before inflation went up so much.... Maybe I'm stupid for switching jobs.... but I'm definitely happier.
Admin
Sleep throws an exception if the thread is interrupted while sleeping, so it's not uncommon to just ignore that.
Admin
This actually an excellent unit test... to test the sanity of the devs.
Admin
My experience of compiler bugs (outside the "optimise for speed" option in VC++ 5 and 6 which were buggier than all hell) is that they are rare but they do exist. Part of my current company's codebase features one module written in C where the coding rules mandate, just for that module, that every goto label is followed immediately by a semicolon. (
labelname:;
). I eventually tracked down an approximate explanation, in that some antique compiler we probably haven't used even once in the last fifteen years (but might in theory use in the future???) would do something stupid if the semicolon wasn't there.Admin
TheCPUWizard/Robin: This is test code. It can be sloppy and repetitive, as long as neither interferes with detecting incorrect program behavior.
Read Robert Martin and other gurus if you want, but don't raise them to dogma. You'll create more problems than you solve.
Admin
Wow, Java is so verbose and hard to read because it doesn't have basic features like indexers, properties or var declarations... it reads like something from the last millennium :O
Admin
I'm thinking the sleep might be the legacy of someone complaining that it ran so fast it couldn't have been actually testing anything.
Admin
Test code is code. It can have bugs, it needs to be maintainable etc. etc. All the same things. Since even best case you end up with AT LEAST as much test code as code (usually more) you need it to be just as good and easy to work with as the rest of the code.
Admin
It takes 30 seconds to run this unit test suite. Wow, that one takes 48 seconds and this other one takes 9 seconds even though the class under test only has four methods. Amazing test coverage.
Admin
I would argue that, in this case, while it might not be uncommon, it is wrong.
That is unless, there's a unit test "fast mode" that is implemented by interrupting the thread from another thread.
Admin
Test code isn't "worked with" in anything like the way that product code is. Cases don't call other cases. The data is purposely concrete, not abstract. Factoring test suites the way that one would factor product code is likely to obscure them.
Admin
"This is test code. It can be sloppy and repetitive, as long as neither interferes with detecting incorrect program behavior." - EXCEPT that test code, experimental code - all of it - are knowledge repositories that may be accessed for years (decades even - I am working on code written in 1992, still using things like OCX along with the latest MAUI and Blazor; and everything in between..... Since there are no developers who have been on the project for 30 years, looking at the revisions of tests and other suplementary artifacts is about 70% of the workload to gain understanding.
Admin
The appliaction I currently fight against doesn't have a single bug or error in any unit test...
you can guess why.