|
I made this argument to my team last year and they were like "yeah but... naaaaaahh". I failed to influence them.
|
# ? Jul 17, 2023 13:16 |
|
|
# ? May 9, 2024 21:19 |
|
I don't really know the difference between fakes and mocks without looking it up. People I know use them interchangeably. To be fair the people I know are pretty dumb. As am I.
|
# ? Jul 17, 2023 14:29 |
|
Plorkyeran posted:Mocking should be a tool of last resort when you can't figure out any other way to test some code, and as such going out of your way to ensure that every class in your codebase can be mocked is just a bad idea. How do you write unit tests without them? Or were you only meaning integration tests?
|
# ? Jul 17, 2023 14:53 |
|
brand engager posted:How do you write unit tests without them? Or were you only meaning integration tests? Pretend your component has a Controller - Service - Delegate way of separating concerns. The Controller takes in the request DTO and returns the response DTO... and the Delegate actually talks to the remote downstream stuff you need.
|
# ? Jul 17, 2023 15:10 |
|
That test delegate sounds like a mock to me
|
# ? Jul 17, 2023 15:25 |
|
brand engager posted:That test delegate sounds like a mock to me Depending on how it's set up, a suitably simple fake and a suitably complicated mock behave roughly the same. I think the value is that if you have 5 different functions in your delegate that mostly do the same thing for the same of testing, like pushing a value onto a container to be retrieved or validated later, writing the fake could end up even easier than writing the mock, and would be significantly easier to understand for someone looking at the test. I can't speak to the code coverage aspect of it, but that sounds pretty nice too.
|
# ? Jul 17, 2023 15:43 |
|
Instead of mocking literally every dependency of literally every class, you're mocking only the stuff that talks to external things... and so you're actually running the end-to-end code of the component itself, in the same way that it's actually used in reality. So, you're covering more lines with fewer tests, you're writing your unit tests in the almost the same way you write your integration tests, and you don't have to worry about fixing your broken unit tests every time you want to make a code change. And since you're spending less time writing and fixing tests, you're also getting stuff done faster.
|
# ? Jul 17, 2023 15:54 |
|
Love Stole the Day posted:Instead of mocking literally every dependency of literally every class, you're mocking only the stuff that talks to external things... and so you're actually running the end-to-end code of the component itself, in the same way that it's actually used in reality. So, you're covering more lines with fewer tests, you're writing your unit tests in the almost the same way you write your integration tests, and you don't have to worry about fixing your broken unit tests every time you want to make a code change. That’s how mocks work, though?
|
# ? Jul 17, 2023 15:56 |
|
Like, why would you write a test that requires mocking everything? Mocks are for the dependencies of the things you put under test as a way to control complex upstream behavior.
|
# ? Jul 17, 2023 15:57 |
|
Volmarias posted:Depending on how it's set up, a suitably simple fake and a suitably complicated mock behave roughly the same. Usually our mocks are like Kotlin code:
|
# ? Jul 17, 2023 16:10 |
|
I just need to vent here so I stop engaging with the person. Please don't condescend to me about how rebases affect public branches when you don't understand how merges, rebases, and Gitlab MRs work. Thank you for coming to my TED talk.
|
# ? Jul 17, 2023 19:51 |
|
brand engager posted:How do you write unit tests without them? Or were you only meaning integration tests? By definition if a mock is involved, you're testing the interaction of two components. If that statement sounds wrong to you, then it's a terminology issue around mocks/stubs/fakes/etc. where you're calling some other kind of test thing a "mock". If you insist on drawing a hard line between unit tests and integration tests but put things specifically testing the interaction of two components under unit tests then I think your categorization is silly. "Tests using mocks aren't unit tests" is sort of a hot take, but really I just think that pretending there's just two distinct categories of tests with a clear line between them is ridiculous and there's a whole gradient of what sorts of dependencies a test has. I see mocks as a tool of last resort because at best you're specifically not testing the thing you've identified as the thing that needs to be tested, and at worst you're testing nothing at all. The more layers in between the code under test and the thing being mocked the more likely it is that the mock makes sense. If you're mocking a direct dependency, then you're mostly just validating that your understanding of that dependency was the same while you were writing the test and the non-test code. This isn't totally worthless and will sometimes help you notice problems, but obviously doesn't help at all with the more important question of if you understood the dependency correctly. If you're mocking something five layers away and are verifying that values are plumbed through correctly, then that's real code being tested even with the mock being involved.
|
# ? Jul 17, 2023 20:13 |
|
And to loop back to the original claim that writing interfaces for every class to enable mocking is dumb: the places where you want to use a mock in a test because the real thing inherently has side effects are nearly always obvious customization points where the interface is semantically meaningful. Your class which sends emails should implement a relevant interface not to enable mocking, but because you don't want to tightly couple your entire application to email sending. The interface-for-every-class rule is specifically requiring interfaces in places where they don't seem necessary to the author, which hopefully means they aren't sensible things to mock in the first place. If they get it wrong, you can just add the interface then.
|
# ? Jul 17, 2023 20:27 |
|
I think all of our code more complicated than truncating a string has dependencies passed into it, and since we only want to test one class at a time in our unit tests that means nearly every test has mocks. Everything calls either another one of our classes or eventually an android component at some point to actually accomplish anything. We don't have any tests where there are multiple classes' real implementations being tested at once which is what I'd call an integration test.
|
# ? Jul 17, 2023 20:38 |
|
That sounds like a lot of work put into making your tests do a worse job of catching bugs.
|
# ? Jul 17, 2023 20:45 |
|
Interfaces, classes, mocks, and tests? How about you interface with my rear end while I mock your testes!!
|
# ? Jul 17, 2023 20:51 |
|
Writing tests against mocks effectively makes your code refactor proof in the sense that any change you make to the underlying classes will instantly break a bunch of tests that explicitly rely on specific methods being called in specific orders, so well done
|
# ? Jul 17, 2023 21:09 |
|
My two favorite things are farting in elevators and rebasing things into dev
|
# ? Jul 17, 2023 21:22 |
|
brand engager posted:I think all of our code more complicated than truncating a string has dependencies passed into it, and since we only want to test one class at a time in our unit tests that means nearly every test has mocks. Everything calls either another one of our classes or eventually an android component at some point to actually accomplish anything. We don't have any tests where there are multiple classes' real implementations being tested at once which is what I'd call an integration test. Yep, this is what people usually mean when they say talk about codebases overusing mocks.
|
# ? Jul 17, 2023 21:49 |
|
Sagacity posted:Writing tests against mocks effectively makes your code refactor proof in the sense that any change you make to the underlying classes will instantly break a bunch of tests that explicitly rely on specific methods being called in specific orders, so well done
|
# ? Jul 17, 2023 22:03 |
|
The big difference between a fake and a mock is that fakes are written by someone who understands the component they're faking, while mock behaviour is configured by someone who just uses that component and may or may not actually understand it.
|
# ? Jul 17, 2023 23:32 |
|
Jabor posted:The big difference between a fake and a mock is that fakes are written by someone who understands the component they're faking, while mock behaviour is configured by someone who just uses that component and may or may not actually understand it.
|
# ? Jul 17, 2023 23:35 |
|
Vulture Culture posted:I've been working with my therapist on active listening, so I'm going to paraphrase to make sure I have this straight. There is no actual big difference between a fake and a mock after it has been written. It has auras projected onto it by its author, who may or may not know what they're doing. Kind of true, but generally you have one fake implementation used everywhere (and fixed everywhere when one person finds any significant unintentional difference with the real system), vs. every single test configuring their own mock behaviour.
|
# ? Jul 17, 2023 23:42 |
|
Jabor posted:Kind of true, but generally you have one fake implementation used everywhere (and fixed everywhere when one person finds any significant unintentional difference with the real system), vs. every single test configuring their own mock behaviour. Or you have a fake per package/module/whatever that all have slightly differing behavior but which one is the correct one?????
|
# ? Jul 18, 2023 01:57 |
|
Sagacity posted:Writing tests against mocks effectively makes your code refactor proof in the sense that any change you make to the underlying classes will instantly break a bunch of tests that explicitly rely on specific methods being called in specific orders, so well done Unit tests in general fight against refactoring, because you are testing things at a certain fixed level of abstraction.
|
# ? Jul 18, 2023 02:01 |
|
smackfu posted:Unit tests in general fight against refactoring, because you are testing things at a certain fixed level of abstraction. Threading this needle very carefully: I would argue that mocks mostly paper over the cracks in badly-designed or over-broad interfaces, by making it easy for developers to only mock out the parts they actually have to care about in the context of their specific behaviors. It's best when devs don't have to do this, but when you're working with something you don't have control over and the alternative is something like Localstack, it's okay to do things a little ugly.
|
# ? Jul 18, 2023 02:22 |
|
I don't care if my tests make it take longer to do refactoring, because then I have to invent one fewer excuse for stand-ups
|
# ? Jul 18, 2023 02:56 |
|
I've spent a ton of time trying to think about testing stuff, but I don't have a ton of experience and I haven't worked on products with a robust existing test suite. But here's my approach (in Python, fwiw) - I don't mock any part of our codebase unless it's extensively tested elsewhere and has a very narrow interface (one example is a ThingValidator that takes in a series of arguments and returns a simple True/False based on whether all those validations pass; we have unique tests for it. - We work with a bunch of clients for various services, and that's the only main thing I patch and mock: the client itself and the responses, which I'll use the actual response class as much as possible if it's not a super complex object (which unfortunately some of ours are, I'm trying to think of a way to build some of these for reuse and still keep them easy to modify.) Building full fakes for them would be a huge amount of effort and we don't have the time, so this will have to do.
|
# ? Jul 18, 2023 19:15 |
|
I frequently mock code, just to let it know what I think about it. Oh yeah, login flow, REALLY GOOD JOB you're doing there when the network request stalls, maybe you should just wait another minute the user definitely won't be spending uninstalling you. Jerk
|
# ? Jul 18, 2023 20:08 |
|
The difference between mocks, fakes, doubles, stubs, etc. is pretty academic and in my experience the terms are not used or distinguished consistently.
|
# ? Jul 19, 2023 00:29 |
|
I had managers once who referred to all testing as unit testing and demanded we unit test everything when they meant they wanted us to make sure it worked before we shipped it
|
# ? Jul 19, 2023 00:49 |
|
Bongo Bill posted:The difference between mocks, fakes, doubles, stubs, etc. is pretty academic and in my experience the terms are not used or distinguished consistently. I don't really understand this point. Like yeah, you can split hairs about whether something is a fake, double, or stub and it doesn't really matter - but a mock is something created by a mocking framework while the others are not, which seems like a pretty bright and well-distinguished line to me.
|
# ? Jul 19, 2023 01:43 |
|
at my last job we had a “unit testing” mysql database that we used in a similar way you’d use an in-memory db, except it was shared. so not only is it not actually unit testing, but you could cause all sorts of fun failures in other peoples tests
|
# ? Jul 19, 2023 02:06 |
|
HamAdams posted:at my last job we had a “unit testing” mysql database that we used in a similar way you’d use an in-memory db, except it was shared. so not only is it not actually unit testing, but you could cause all sorts of fun failures in other peoples tests I like when that kind of setup in a five year old application someone wants me to rehabilitat, and it turns out the dev server with that db is long gone
|
# ? Jul 19, 2023 03:56 |
|
whats the difference between a v&v engineer and a test engineer?
|
# ? Jul 19, 2023 05:52 |
|
sdet that's the way u like 2 b
|
# ? Jul 19, 2023 06:40 |
|
Jabor posted:I don't really understand this point. Like yeah, you can split hairs about whether something is a fake, double, or stub and it doesn't really matter - but a mock is something created by a mocking framework while the others are not, which seems like a pretty bright and well-distinguished line to me. The difference is not really that important. If I tell someone, "Oh you'll need to mock out that dependency", and they proceed to make a fake. I'm not gonna care, and the difference is immaterial.
|
# ? Jul 19, 2023 12:42 |
|
This is development. It’s perfectly reasonable there are precise terms for things AND that people don’t use them precisely.
|
# ? Jul 19, 2023 13:21 |
|
AmbientParadox posted:whats the difference between a v&v engineer and a test engineer? Industry, mostly. Verification and validation are specific testing-related activities defined in ISO 9001, so if you see a job posting for a v&v engineer you can be pretty sure it's in an industry that cares about that particular standard.
|
# ? Jul 19, 2023 15:00 |
|
|
# ? May 9, 2024 21:19 |
|
smackfu posted:This is development. It’s perfectly reasonable there are precise terms for things AND that people get really pedantic about everything.
|
# ? Jul 19, 2023 17:21 |