Details
-
AboutRants a lot, loves tech since 5.
-
SkillsCode data algo design architecture music cricket hockey telecom finance phm python Java Linux CF aws azure heroku
Joined devRant on 6/27/2017
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
-
To anyone new to the corporate world I have this advice: there's a game no one tells you about in school or university. It's a game of politics. The good news is that you can choose not to play the game. The bad news is that others who do can change that decision for you, if you give them a reason to. So here's my tips to keep yourself from common bad situations:
* Some people will say they'd "prefer that people were honest". This is an outright lie.
* Be guarded - if a scenario could be taken out of context assume it will be.
* Mimic the office culture, don't try to rock the boat.
* Be polite, but always stay neutral between colleagues, picking a side means you're playing the game. Unless that side is your company vs another company in which case-- you are 100% on the company side and everyone else is stupid and incompetent.4 -
"I'm almost done, I'll just need to add tests!"
Booom! You did it, that was a nuke going off in my head.
No, you shouldn't just need to add tests. The tests should have been written from the get go! You most likely won't cover all the cases. You won't know if adding the tests will break your feature, as you had none, as you refactor your untested mess in order to make your code testable.
When reading your mess of a test case and the painful mocking process you went through, I silently cry out into the void: "Why oh why!? All of this suffering could have been avoided!"
Since most of the time, your mocking pain boils down to not understanding what your "unit" in your "unit test" should be.
So let it be said:
- If you want to build a parser for an XML file, then just write a function / class whose *only* purpose is: parse the XML file, return a value object. That's it. Nothing more, nothing less.
- If you want to build a parser for an XML file, it MUST NOT: download a zip, extract that zip, merge all those files to one big file, parse that big file, talk to some other random APIs as a side-effect, and then return a value object.
Because then you suddenly have to mock away a http service and deal with zip files in your test cases.
The http util of your programming language will most likely work. Your unzip library will most likely work. So just assume it working. There are valid use cases where you want to make sure you acutally send a request and get a response, yet I am talking unit test here only.
In the scope of a class, keep the public methods to a reasonable minimum. As for each public method you shall at least create one test case. If you ever have the feeling "I want to test that private method" replace that statement in your head with: "I should extract that functionality to a new class where that method public. I then can create a unit test case a for that." That new service then becomes a dependency in your current service. Problem solved.
Also, mocking away dependencies should a simple process. If your mocking process fills half the screen, your test setup is overly complicated and your class is doing too much.
That's why I currently dig functional programming so much. When you build pure functions without side effects, unit tests are easy to write. Yet you can apply pure functions to OOP as well (to a degree). Embrace immutability.
Sidenote:
It's really not helpful that a lot of developers don't understand the difference between unit, functional acceptance, integration testing. Then they wonder why they can't test something easily, write overly complex test cases, until someone points out to them: No, in the scope of unit tests, we don't need to test our persistance layer. We just assume that it works. We should only test our businsess logic. You know: "Assuming that I get that response from the database, I expect that to happen." You don't need a test db, make a real query against that, in order to test that. (That still is a valid thing to do. Yet not in the scope of unit tests.)rant developer unit test test testing fp oop writing tests get your shit together unit testing unit tests8 -
Fucking clueless products owners.
Him: "I want a mobile app - how long"
Me: "Depends, what should it do?"
Him: "Dunno"
Me: "Well what problem should it solve?"
Him: "Dunno"
Me: "Who's it for?"
Him: "Dunno"
Me: "Well I can't help you then!"
Him: "I need an estimate for my business plan"
Me: "OK - put 'eternity' down, and we can work backwards from there"
Jackass7