The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
I hate mock. I mean not in general, in general I don't care I just think they are a waste of time.
But I particularly hate them in the case of automated testing.
Not only they make you waste time writing code to set them up in each test, but then you are not testing the real thing, you are testing mocks!
Now the funny thing is, I had some unit test that validated some functionality as working but it was not working for the user and I was completely puzzled...
After writing a little app to test the real thing, turns out I had one insidious mock in my test. Just one. And that was the one thing that worked in the test but failed in the real app!
On top of that it was completely unneeded.. the real interface would have worked just as well (or failed, in that case)
Well, they're unit tests, so you're testing units, not multiple units or entire systems (other tests exist for that).
And from the perspective of the unit you're testing it doesn't really matter if IRepository.GetData gets the data from a database, a service or a mock.
From the perspective of the test is does matter since the database and service can't be controlled from the test scenario, but a mock can.
A mock will always return x when the input is y, a database or service might not.
And then the thing you're actually testing can always use value x which should always return value z, which can be asserted.
// Contrived example:publicint AddOneToDbField(IRepository repo)
int dbField = repo.GetNumber(); // This should be mocked.return dbField + 1; // This should be tested and asserted.
If you want to test your repository you should do stuff like integration testing, although I've also seen unit tests that connect to databases.
But if you're testing your mocks you might not be doing it right
"Unanswered" is a bit of a misnomer as some have been "de-answered".
Take a look at the top one on the list, for example - it's protected due to answers having to be removed. Whether that's an OP not accepting one or an overzealous mod or a genuine case of all the answers being totally unhelpful, we will never know.
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
A few times, I tried to get help from the SO community. Every single time, I was met with insults, of the kind "Something similar to this was answered way back in 2003 - what kind of idiot are you that cannot dig up that answer and stop bothering us?"
I guess that a sizable fraction of those five million help seekers have come to the same conclusion than I have: Trying to push something on SO is futile. You can search it to see if anyone has run into exactly the same problem as you have, and received decent help. If not, search somewhere else for an answer.
I'd be curious to know how many unique users are behind those five million questions. But the really interesting question is how many have recieved more or less insulting answers, like me, and then decided that SO is not a place to get help. Software masochists may get some satisfaction there, but I happen not to be in that group.
Yeah, I agree. SO can be a very bad experience. And, if you can believe it, I've had an even worse time at electronics.stackexchange.com (stackexchange is the parent to SO and the site is related).
At one point I asked a question about voltage ratings on capacitors that I really wanted to know the answer about and they literally deleted my question and it took me a long time to write it up so that it was detailed and meaningful.